use of org.mockito.ArgumentMatcher in project hbase by apache.
the class TestCanaryTool method testRegionserverWithRegions.
//by creating a table, there shouldn't be any region servers not serving any regions
@Test
public void testRegionserverWithRegions() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
testingUtility.createTable(tableName, new byte[][] { FAMILY });
runRegionserverCanary();
verify(mockAppender, never()).doAppend(argThat(new ArgumentMatcher<LoggingEvent>() {
@Override
public boolean matches(Object argument) {
return ((LoggingEvent) argument).getRenderedMessage().contains("Regionserver not serving any regions");
}
}));
}
use of org.mockito.ArgumentMatcher in project hadoop by apache.
the class TestRM method testKillFailingApp.
// Test Kill an app while the app is failing
@Test(timeout = 30000)
public void testKillFailingApp() throws Exception {
// this dispatcher ignores RMAppAttemptEventType.KILL event
final Dispatcher dispatcher = new DrainDispatcher() {
@Override
public EventHandler<Event> getEventHandler() {
class EventArgMatcher extends ArgumentMatcher<AbstractEvent> {
@Override
public boolean matches(Object argument) {
if (argument instanceof RMAppAttemptEvent) {
if (((RMAppAttemptEvent) argument).getType().equals(RMAppAttemptEventType.KILL)) {
return true;
}
}
return false;
}
}
EventHandler handler = spy(super.getEventHandler());
doNothing().when(handler).handle(argThat(new EventArgMatcher()));
return handler;
}
};
MockRM rm1 = new MockRM(conf) {
@Override
protected Dispatcher createDispatcher() {
return dispatcher;
}
};
rm1.start();
MockNM nm1 = new MockNM("127.0.0.1:1234", 8192, rm1.getResourceTrackerService());
nm1.registerNode();
RMApp app1 = rm1.submitApp(200);
MockAM am1 = MockRM.launchAndRegisterAM(app1, rm1, nm1);
rm1.killApp(app1.getApplicationId());
// fail the app by sending container_finished event.
nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 1, ContainerState.COMPLETE);
rm1.waitForState(am1.getApplicationAttemptId(), RMAppAttemptState.FAILED);
// app is killed, not launching a new attempt
rm1.waitForState(app1.getApplicationId(), RMAppState.KILLED);
}
use of org.mockito.ArgumentMatcher in project storm by apache.
the class KafkaBoltTest method testSimple.
@SuppressWarnings({ "unchecked", "serial" })
@Test
public void testSimple() {
final KafkaProducer<String, String> producer = mock(KafkaProducer.class);
when(producer.send(any(), any())).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Callback c = (Callback) invocation.getArguments()[1];
c.onCompletion(null, null);
return null;
}
});
KafkaBolt<String, String> bolt = new KafkaBolt<String, String>() {
@Override
protected KafkaProducer<String, String> mkProducer(Properties props) {
return producer;
}
};
bolt.withTopicSelector("MY_TOPIC");
OutputCollector collector = mock(OutputCollector.class);
TopologyContext context = mock(TopologyContext.class);
Map<String, Object> conf = new HashMap<>();
bolt.prepare(conf, context, collector);
MkTupleParam param = new MkTupleParam();
param.setFields("key", "message");
Tuple testTuple = Testing.testTuple(Arrays.asList("KEY", "VALUE"), param);
bolt.execute(testTuple);
verify(producer).send(argThat(new ArgumentMatcher<ProducerRecord<String, String>>() {
@Override
public boolean matches(Object argument) {
LOG.info("GOT {} ->", argument);
ProducerRecord<String, String> arg = (ProducerRecord<String, String>) argument;
LOG.info(" {} {} {}", arg.topic(), arg.key(), arg.value());
return "MY_TOPIC".equals(arg.topic()) && "KEY".equals(arg.key()) && "VALUE".equals(arg.value());
}
}), any(Callback.class));
verify(collector).ack(testTuple);
}
use of org.mockito.ArgumentMatcher in project facebook-android-sdk by facebook.
the class LoginManagerTest method implTestLogInCreatesPendingRequestWithCorrectValues.
public void implTestLogInCreatesPendingRequestWithCorrectValues(LoginManager loginManager, final Collection<String> expectedPermissions) {
ArgumentMatcher<Intent> m = new ArgumentMatcher<Intent>() {
@Override
public boolean matches(Object argument) {
Intent orig = (Intent) argument;
Bundle bundle = orig.getBundleExtra(LoginFragment.REQUEST_KEY);
LoginClient.Request request = (LoginClient.Request) bundle.getParcelable(LoginFragment.EXTRA_REQUEST);
assertEquals(MOCK_APP_ID, request.getApplicationId());
assertEquals(LoginBehavior.NATIVE_ONLY, request.getLoginBehavior());
assertEquals(DefaultAudience.EVERYONE, request.getDefaultAudience());
Set<String> permissions = request.getPermissions();
for (String permission : expectedPermissions) {
assertTrue(permissions.contains(permission));
}
return true;
}
};
int loginRequestCode = CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode();
verify(mockActivity, times(1)).startActivityForResult(argThat(m), eq(loginRequestCode));
}
use of org.mockito.ArgumentMatcher in project androidannotations by androidannotations.
the class MyServiceTest method cookieInUrl.
@Test
public void cookieInUrl() {
final String xtValue = "1234";
final String sjsaidValue = "7890";
final String locationValue = "somePlace";
final int yearValue = 2013;
MyService_ myService = new MyService_(null);
RestTemplate restTemplate = mock(RestTemplate.class);
myService.setRestTemplate(restTemplate);
addPendingResponse("{'id':1,'name':'event1'}");
// normally this is set by a call like authenticate()
// which is annotated with @SetsCookie
myService.setCookie("xt", xtValue);
myService.setCookie("sjsaid", sjsaidValue);
myService.setHttpBasicAuth("fancyUser", "fancierPassword");
myService.getEventsVoid(locationValue, yearValue);
ArgumentMatcher<HttpEntity<Void>> matcher = new ArgumentMatcher<HttpEntity<Void>>() {
@Override
public boolean matches(HttpEntity<Void> argument) {
final String expected = "sjsaid=" + sjsaidValue + ";";
return expected.equals(argument.getHeaders().get("Cookie").get(0));
}
};
Map<String, Object> urlVariables = new HashMap<String, Object>();
urlVariables.put("location", locationValue);
urlVariables.put("year", yearValue);
urlVariables.put("xt", xtValue);
verify(restTemplate).exchange(Matchers.anyString(), Matchers.<HttpMethod>any(), argThat(matcher), Matchers.<Class<Object>>any(), eq(urlVariables));
}
Aggregations