List of usage examples for com.rabbitmq.client ConsumerCancelledException ConsumerCancelledException
ConsumerCancelledException
From source file:pl.nask.hsn2.DataStoreActiveCleanerTest.java
License:Open Source License
@SuppressWarnings({ "rawtypes", "unused" }) private void mockObjects() throws Exception { connCloseRequested = false;//from ww w. j a va 2 s .c o m new NonStrictExpectations() { @Mocked ConnectionFactory cf; { // Create new connection. cf.newConnection(); result = c; // Create channel. c.createChannel(); result = ch; // Close connection. c.close(); forEachInvocation = new Object() { void validate() { connCloseRequested = true; } }; // Declare exchange. ch.exchangeDeclare(anyString, anyString); // Declare queue. ch.queueDeclare(); result = dok; // Get queue name. dok.getQueue(); consumer.nextDelivery(); result = new Delegate() { public Delivery nextDelivery() throws Exception { Thread.sleep(100); Delivery d = null; Envelope envelope; BasicProperties properties; JobFinished jf; byte[] body; switch (nextAction) { case TASK_ACCEPTED: d = taskAcceptedMsg(); nextAction = CleaningActions.REMOVE_JOB_1; break; case REMOVE_JOB_1: d = removeJobFinished(1, JobStatus.COMPLETED); nextAction = CleaningActions.REMOVE_JOB_2; break; case REMOVE_JOB_2: d = removeJobFinishedReminder(2); nextAction = CleaningActions.CANCEL; break; case REMOVE_JOB_3: d = removeJobFinished(3, JobStatus.COMPLETED); nextAction = CleaningActions.REMOVE_JOB_3_AGAIN; break; case REMOVE_JOB_3_AGAIN: d = removeJobFinished(3, JobStatus.COMPLETED); nextAction = CleaningActions.CANCEL; break; case REMOVE_JOB_4: d = removeJobFinished(4, JobStatus.COMPLETED); nextAction = CleaningActions.CANCEL; break; case REMOVE_JOB_5: d = removeJobFinished(5, JobStatus.FAILED); nextAction = CleaningActions.CANCEL; break; case NEVER_RETURN: while (true) { LOGGER.debug("Never return..."); Thread.sleep(10000); } case CANCEL: throw new ConsumerCancelledException(); case INTERRUPT: throw new InterruptedException("Test interruption"); case SHUTDOWN: throw new ShutdownSignalException(false, false, null, null); case IO_EXCEPTION: throw new IOException("Test I/O exception"); } return d; } private Delivery taskAcceptedMsg() { Delivery d; Envelope envelope; BasicProperties properties; JobFinished jf; byte[] body; envelope = new Envelope(1, false, "", ""); properties = new BasicProperties.Builder().type("TaskAccepted").build(); body = new byte[] { 1 }; d = new Delivery(envelope, properties, body); return d; } private Delivery removeJobFinished(long jobId, JobStatus status) { Delivery d; Envelope envelope; BasicProperties properties; JobFinished jf; byte[] body; envelope = new Envelope(1, false, "", ""); properties = new BasicProperties.Builder().type("JobFinished").build(); jf = JobFinished.newBuilder().setJob(jobId).setStatus(status).build(); body = jf.toByteArray(); d = new Delivery(envelope, properties, body); return d; } private Delivery removeJobFinishedReminder(long jobId) { Delivery d; Envelope envelope; BasicProperties properties; byte[] body; envelope = new Envelope(1, false, "", ""); properties = new BasicProperties.Builder().type("JobFinishedReminder").build(); JobFinishedReminder jfr = JobFinishedReminder.newBuilder().setJob(jobId) .setStatus(JobStatus.COMPLETED).build(); body = jfr.toByteArray(); d = new Delivery(envelope, properties, body); return d; } }; } }; }