Search in sources :

Example 1 with IPromise

use of com.aphyr.riemann.client.IPromise in project nifi by apache.

the class TestPutRiemann method getTestRunner.

private TestRunner getTestRunner(final boolean failOnWrite) {
    RiemannClient riemannClient = mock(RiemannClient.class);
    when(riemannClient.sendEvents(anyListOf(Proto.Event.class))).thenAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            List<Proto.Event> events = (List<Proto.Event>) invocationOnMock.getArguments()[0];
            for (Proto.Event event : events) {
                eventStream.add(event);
            }
            IPromise iPromise = mock(IPromise.class);
            if (!failOnWrite) {
                when(iPromise.deref(anyInt(), any(TimeUnit.class))).thenReturn(Proto.Msg.getDefaultInstance());
            } else {
                when(iPromise.deref(anyInt(), any(TimeUnit.class))).thenReturn(null);
            }
            return iPromise;
        }
    });
    when(riemannClient.isConnected()).thenReturn(true);
    PutRiemann riemannProcessor = new PutRiemann();
    riemannProcessor.riemannClient = riemannClient;
    riemannProcessor.transport = PutRiemann.Transport.TCP;
    TestRunner runner = TestRunners.newTestRunner(riemannProcessor);
    runner.setProperty(PutRiemann.RIEMANN_HOST, "localhost");
    runner.setProperty(PutRiemann.RIEMANN_PORT, "5555");
    runner.setProperty(PutRiemann.TRANSPORT_PROTOCOL, "TCP");
    runner.setProperty(PutRiemann.BATCH_SIZE, "100");
    runner.setProperty(PutRiemann.ATTR_SERVICE, "nifi-test-service");
    runner.setProperty(PutRiemann.ATTR_HOST, "${riemann.host}");
    runner.setProperty(PutRiemann.ATTR_TTL, "5");
    runner.setProperty(PutRiemann.ATTR_DESCRIPTION, "test");
    runner.setProperty(PutRiemann.ATTR_TAGS, "tag1, tag2, tag3");
    runner.setProperty(PutRiemann.ATTR_METRIC, "${riemann.metric}");
    runner.setProperty("custom-attribute-1", "${custom.attribute.1}");
    runner.setProperty("custom-attribute-2", "${custom.attribute.2}");
    runner.setProperty("custom-attribute-3", "${custom.attribute.3}");
    return runner;
}
Also used : Answer(org.mockito.stubbing.Answer) IPromise(com.aphyr.riemann.client.IPromise) RiemannClient(com.aphyr.riemann.client.RiemannClient) Proto(com.aphyr.riemann.Proto) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TestRunner(org.apache.nifi.util.TestRunner) LinkedList(java.util.LinkedList) List(java.util.List)

Aggregations

Proto (com.aphyr.riemann.Proto)1 IPromise (com.aphyr.riemann.client.IPromise)1 RiemannClient (com.aphyr.riemann.client.RiemannClient)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TestRunner (org.apache.nifi.util.TestRunner)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1