List of usage examples for org.apache.commons.lang3.mutable MutableObject MutableObject
public MutableObject(final T value)
From source file:org.jtestplatform.common.transport.TransportHelperTest.java
@Test public void testSendRequest() throws TransportException { // prepare/* w w w . j a va2 s .co m*/ MessageData requestData = MessageData.GETTESTFRAMEWORKS; MessageData answerData = MessageData.TESTFRAMEWORKS; final Message requestMessage = spy(requestData.createMessage()); final Message answerMessage = spy(answerData.createMessage()); Transport transport = mock(Transport.class); when(transport.receive()).thenReturn(answerData.messageClass.getName(), answerData.expectedParts); final MutableObject<Boolean> sendImplCalled = new MutableObject<Boolean>(false); final MutableObject<Boolean> receiveImplCalled = new MutableObject<Boolean>(false); TransportHelper helper = new TransportHelper() { @Override protected void sendImpl(Transport transport, Message message) throws TransportException { sendImplCalled.setValue(true); super.sendImpl(transport, message); } @Override protected Message receiveImpl(Transport transport) throws TransportException { receiveImplCalled.setValue(true); return super.receiveImpl(transport); } @Override Message createMessage(Class<? extends Message> clazz) throws InstantiationException, IllegalAccessException { return answerMessage; } }; // test Message actualAnswerMessage = helper.sendRequest(transport, requestMessage); // verify assertThat(sendImplCalled.getValue()).as("sendImpl called").isTrue(); assertThat(receiveImplCalled.getValue()).as("receiveImpl called").isTrue(); assertThat(actualAnswerMessage).as("actual answer").isSameAs(answerMessage); }
From source file:org.jtestplatform.common.transport.TransportHelperTest.java
@Theory public void testSend(MessageData data) throws TransportException, InstantiationException, IllegalAccessException { // prepare/*from w ww. j a v a 2 s .c om*/ Message message = spy(data.createMessage()); Transport transport = mock(Transport.class); final MutableObject<Boolean> called = new MutableObject<Boolean>(false); TransportHelper helper = new TransportHelper() { @Override protected void sendImpl(Transport transport, Message message) throws TransportException { called.setValue(true); super.sendImpl(transport, message); } }; // test helper.send(transport, message); // verify assertThat(called.getValue()).as("sendImpl called").isTrue(); InOrder inOrder = inOrder(transport, message); inOrder.verify(transport, times(1)).send(eq(message.getClass().getName())); inOrder.verify(message, times(1)).sendWith(eq(transport)); for (int i = 0; i < data.expectedParts.length; i++) { inOrder.verify(transport, times(1)).send(eq(data.expectedParts[i])); } inOrder.verifyNoMoreInteractions(); }
From source file:org.mitre.mpf.wfm.camel.JobCompleteProcessorImpl.java
@Override public void wfmProcess(Exchange exchange) throws WfmProcessingException { Long jobId = exchange.getIn().getHeader(MpfHeaders.JOB_ID, Long.class); assert jobId != null : String.format("The header '%s' (value=%s) was not set or is not a Long.", MpfHeaders.JOB_ID, exchange.getIn().getHeader(MpfHeaders.JOB_ID)); if (jobId == Long.MIN_VALUE) { // If we receive a very large negative Job ID, it means an exception was encountered during processing of a job, // and none of the provided error handling logic could fix it. Further processing should not be performed. log.warn(// www . j av a2s .c o m "[Job {}:*:*] An error prevents a job from completing successfully. Please review the logs for additional information.", jobId); } else { String statusString = exchange.getIn().getHeader(MpfHeaders.JOB_STATUS, String.class); Mutable<JobStatus> jobStatus = new MutableObject<>(JobStatus.parse(statusString, JobStatus.UNKNOWN)); markJobStatus(jobId, jobStatus.getValue()); try { markJobStatus(jobId, JobStatus.BUILDING_OUTPUT_OBJECT); // NOTE: jobStatus is mutable - it __may__ be modified in createOutputObject! createOutputObject(jobId, jobStatus); } catch (Exception exception) { log.warn("Failed to create the output object for Job {} due to an exception.", jobId, exception); jobStatus.setValue(JobStatus.ERROR); } markJobStatus(jobId, jobStatus.getValue()); try { callback(jobId); } catch (Exception exception) { log.warn("Failed to make callback (if appropriate) for Job #{}.", jobId); } // Tear down the job. try { destroy(jobId); } catch (Exception exception) { log.warn( "Failed to clean up Job {} due to an exception. Data for this job will remain in the transient data store, but the status of the job has not been affected by this failure.", jobId, exception); } JobCompleteNotification jobCompleteNotification = new JobCompleteNotification( exchange.getIn().getHeader(MpfHeaders.JOB_ID, Long.class)); for (NotificationConsumer<JobCompleteNotification> consumer : consumers) { if (!jobCompleteNotification.isConsumed()) { try { consumer.onNotification(this, new JobCompleteNotification( exchange.getIn().getHeader(MpfHeaders.JOB_ID, Long.class))); } catch (Exception exception) { log.warn("Completion consumer '{}' threw an exception.", consumer, exception); } } } AtmosphereController.broadcast(new JobStatusMessage(jobId, 100, jobStatus.getValue(), new Date())); jobProgressStore.setJobProgress(jobId, 100.0f); log.info("[Job {}:*:*] Job complete!", jobId); } }