use of org.mockito.stubbing.Answer in project flink by apache.
the class YarnApplicationMasterRunnerTest method testCreateTaskExecutorContext.
@Test
public void testCreateTaskExecutorContext() throws Exception {
File root = folder.getRoot();
File home = new File(root, "home");
boolean created = home.mkdir();
assertTrue(created);
Answer<?> getDefault = new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
return invocationOnMock.getArguments()[1];
}
};
Configuration flinkConf = new Configuration();
YarnConfiguration yarnConf = mock(YarnConfiguration.class);
doAnswer(getDefault).when(yarnConf).get(anyString(), anyString());
doAnswer(getDefault).when(yarnConf).getInt(anyString(), anyInt());
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
return new String[] { (String) invocationOnMock.getArguments()[1] };
}
}).when(yarnConf).getStrings(anyString(), Mockito.<String>anyVararg());
Map<String, String> env = ImmutableMap.<String, String>builder().put(ENV_APP_ID, "foo").put(ENV_CLIENT_HOME_DIR, home.getAbsolutePath()).put(ENV_CLIENT_SHIP_FILES, "").put(ENV_FLINK_CLASSPATH, "").put(ENV_HADOOP_USER_NAME, "foo").put(FLINK_JAR_PATH, root.toURI().toString()).build();
ContaineredTaskManagerParameters tmParams = mock(ContaineredTaskManagerParameters.class);
Configuration taskManagerConf = new Configuration();
String workingDirectory = root.getAbsolutePath();
Class<?> taskManagerMainClass = YarnApplicationMasterRunnerTest.class;
ContainerLaunchContext ctx = Utils.createTaskExecutorContext(flinkConf, yarnConf, env, tmParams, taskManagerConf, workingDirectory, taskManagerMainClass, LOG);
assertEquals("file", ctx.getLocalResources().get("flink.jar").getResource().getScheme());
}
use of org.mockito.stubbing.Answer in project flink by apache.
the class StreamTestSingleInputGate method setupInputChannels.
@SuppressWarnings("unchecked")
private void setupInputChannels() throws IOException, InterruptedException {
for (int i = 0; i < numInputChannels; i++) {
final int channelIndex = i;
final RecordSerializer<SerializationDelegate<Object>> recordSerializer = new SpanningRecordSerializer<SerializationDelegate<Object>>();
final SerializationDelegate<Object> delegate = (SerializationDelegate<Object>) (SerializationDelegate<?>) new SerializationDelegate<StreamElement>(new StreamElementSerializer<T>(serializer));
inputQueues[channelIndex] = new ConcurrentLinkedQueue<InputValue<Object>>();
inputChannels[channelIndex] = new TestInputChannel(inputGate, i);
final Answer<BufferAndAvailability> answer = new Answer<BufferAndAvailability>() {
@Override
public BufferAndAvailability answer(InvocationOnMock invocationOnMock) throws Throwable {
InputValue<Object> input = inputQueues[channelIndex].poll();
if (input != null && input.isStreamEnd()) {
when(inputChannels[channelIndex].getInputChannel().isReleased()).thenReturn(true);
return new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE), false);
} else if (input != null && input.isStreamRecord()) {
Object inputElement = input.getStreamRecord();
final Buffer buffer = new Buffer(MemorySegmentFactory.allocateUnpooledSegment(bufferSize), mock(BufferRecycler.class));
recordSerializer.setNextBuffer(buffer);
delegate.setInstance(inputElement);
recordSerializer.addRecord(delegate);
// Call getCurrentBuffer to ensure size is set
return new BufferAndAvailability(recordSerializer.getCurrentBuffer(), false);
} else if (input != null && input.isEvent()) {
AbstractEvent event = input.getEvent();
return new BufferAndAvailability(EventSerializer.toBuffer(event), false);
} else {
synchronized (inputQueues[channelIndex]) {
inputQueues[channelIndex].wait();
return answer(invocationOnMock);
}
}
}
};
when(inputChannels[channelIndex].getInputChannel().getNextBuffer()).thenAnswer(answer);
inputGate.setInputChannel(new IntermediateResultPartitionID(), inputChannels[channelIndex].getInputChannel());
}
}
use of org.mockito.stubbing.Answer in project camel by apache.
the class CouchbaseProducerTest method testTimeOutRetryThenSuccess.
@Test
public void testTimeOutRetryThenSuccess() throws Exception {
OperationFuture of = mock(OperationFuture.class);
when(of.get()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Exception {
throw new RuntimeException("Timed out waiting for operation");
}
}).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Exception {
return true;
}
});
when(client.set(org.mockito.Matchers.anyString(), org.mockito.Matchers.anyInt(), org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class), org.mockito.Matchers.any(ReplicateTo.class))).thenReturn(of);
when(endpoint.getId()).thenReturn("123");
when(endpoint.getOperation()).thenReturn("CCB_PUT");
when(exchange.getOut()).thenReturn(msg);
producer.process(exchange);
verify(of, times(2)).get();
verify(msg).setBody(true);
}
use of org.mockito.stubbing.Answer in project camel by apache.
the class CouchbaseProducerTest method testTimeOutRetryTwiceThenSuccess.
@Test
public void testTimeOutRetryTwiceThenSuccess() throws Exception {
OperationFuture of = mock(OperationFuture.class);
when(of.get()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Exception {
throw new RuntimeException("Timed out waiting for operation");
}
}).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Exception {
throw new RuntimeException("Timed out waiting for operation");
}
}).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Exception {
return true;
}
});
when(client.set(org.mockito.Matchers.anyString(), org.mockito.Matchers.anyInt(), org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class), org.mockito.Matchers.any(ReplicateTo.class))).thenReturn(of);
when(endpoint.getId()).thenReturn("123");
when(endpoint.getOperation()).thenReturn("CCB_PUT");
when(exchange.getOut()).thenReturn(msg);
producer.process(exchange);
verify(of, times(3)).get();
verify(msg).setBody(true);
}
use of org.mockito.stubbing.Answer in project byte-buddy by raphw.
the class AgentBuilderDefaultTest method testExecutingTransformerDoesNotRecurse.
@Test
@SuppressWarnings("unchecked")
public void testExecutingTransformerDoesNotRecurse() throws Exception {
final AgentBuilder.Default.ExecutingTransformer executingTransformer = new AgentBuilder.Default.ExecutingTransformer(byteBuddy, listener, poolStrategy, typeStrategy, locationStrategy, mock(AgentBuilder.Default.NativeMethodStrategy.class), initializationStrategy, mock(AgentBuilder.Default.BootstrapInjectionStrategy.class), AgentBuilder.LambdaInstrumentationStrategy.DISABLED, AgentBuilder.DescriptionStrategy.Default.HYBRID, mock(AgentBuilder.FallbackStrategy.class), mock(AgentBuilder.InstallationListener.class), mock(AgentBuilder.RawMatcher.class), mock(AgentBuilder.Default.Transformation.class), new AgentBuilder.Default.CircularityLock.Default());
final ClassLoader classLoader = mock(ClassLoader.class);
final ProtectionDomain protectionDomain = mock(ProtectionDomain.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertThat(executingTransformer.transform(classLoader, FOO, Object.class, protectionDomain, new byte[0]), nullValue(byte[].class));
return null;
}
}).when(listener).onComplete(FOO, classLoader, JavaModule.UNSUPPORTED, true);
assertThat(executingTransformer.transform(classLoader, FOO, Object.class, protectionDomain, new byte[0]), nullValue(byte[].class));
verify(listener).onComplete(FOO, classLoader, JavaModule.UNSUPPORTED, true);
}
Aggregations