Search in sources :

Example 56 with ArgumentMatcher

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");
        }
    }));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ArgumentMatcher(org.mockito.ArgumentMatcher) Test(org.junit.Test)

Example 57 with ArgumentMatcher

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);
}
Also used : DrainDispatcher(org.apache.hadoop.yarn.event.DrainDispatcher) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) ArgumentMatcher(org.mockito.ArgumentMatcher) AbstractEvent(org.apache.hadoop.yarn.event.AbstractEvent) Event(org.apache.hadoop.yarn.event.Event) RMAppAttemptEvent(org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptEvent) RMAppEvent(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppEvent) EventHandler(org.apache.hadoop.yarn.event.EventHandler) Dispatcher(org.apache.hadoop.yarn.event.Dispatcher) DrainDispatcher(org.apache.hadoop.yarn.event.DrainDispatcher) RMAppAttemptEvent(org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptEvent) Test(org.junit.Test)

Example 58 with ArgumentMatcher

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);
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) HashMap(java.util.HashMap) Properties(java.util.Properties) Callback(org.apache.kafka.clients.producer.Callback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentMatcher(org.mockito.ArgumentMatcher) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) MkTupleParam(org.apache.storm.testing.MkTupleParam) TopologyContext(org.apache.storm.task.TopologyContext) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 59 with ArgumentMatcher

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));
}
Also used : Bundle(android.os.Bundle) ArgumentMatcher(org.mockito.ArgumentMatcher) Intent(android.content.Intent)

Example 60 with ArgumentMatcher

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));
}
Also used : HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap) ArgumentMatcher(org.mockito.ArgumentMatcher) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Aggregations

ArgumentMatcher (org.mockito.ArgumentMatcher)104 Test (org.junit.Test)82 Appender (ch.qos.logback.core.Appender)23 Logger (org.slf4j.Logger)23 ArrayList (java.util.ArrayList)19 Context (android.content.Context)14 Channel (com.microsoft.azure.mobile.channel.Channel)13 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)13 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Intent (android.content.Intent)11 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)10 FeaturesService (org.apache.karaf.features.FeaturesService)10 ResolveInfo (android.content.pm.ResolveInfo)9 File (java.io.File)9 Repository (org.apache.karaf.features.Repository)9 Matchers.anyString (org.mockito.Matchers.anyString)9 UUID (java.util.UUID)8 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)8 Log (com.microsoft.azure.mobile.ingestion.models.Log)7