Search in sources :

Example 1 with DummySerializer

use of com.nextdoor.bender.testutils.DummySerializerHelper.DummySerializer in project bender by Nextdoor.

the class SerializerProcessorTest method testStatsLoggingOnError.

@Test
public void testStatsLoggingOnError() {
    DummySerializer serializer = mock(DummySerializer.class);
    SerializerProcessor processor = new SerializerProcessor(serializer);
    doThrow(new RuntimeException()).when(serializer).serialize("foo");
    /*
     * Mock the Stat object
     */
    Stat runtimeStat = mock(Stat.class);
    Stat successStat = mock(Stat.class);
    Stat errorStat = mock(Stat.class);
    processor.setRuntimeStat(runtimeStat);
    processor.setSuccessCountStat(successStat);
    processor.setErrorCountStat(errorStat);
    try {
        processor.serialize("foo");
    } catch (Exception e) {
    // expected
    }
    /*
     * Verify start, stop are called, increment error count and never increment success count.
     */
    verify(runtimeStat, times(1)).start();
    verify(runtimeStat, times(1)).stop();
    verify(successStat, never()).increment();
    verify(errorStat, times(1)).increment();
}
Also used : DummySerializer(com.nextdoor.bender.testutils.DummySerializerHelper.DummySerializer) Stat(com.nextdoor.bender.monitoring.Stat) Test(org.junit.Test)

Example 2 with DummySerializer

use of com.nextdoor.bender.testutils.DummySerializerHelper.DummySerializer in project bender by Nextdoor.

the class SerializerProcessorTest method testSerializeNull.

@Test
public void testSerializeNull() {
    DummySerializer serializer = mock(DummySerializer.class);
    SerializerProcessor processor = new SerializerProcessor(serializer);
    doThrow(new RuntimeException()).when(serializer).serialize(null);
    /*
     * Mock the Stat object
     */
    Stat runtimeStat = mock(Stat.class);
    Stat successStat = mock(Stat.class);
    Stat errorStat = mock(Stat.class);
    processor.setRuntimeStat(runtimeStat);
    processor.setSuccessCountStat(successStat);
    processor.setErrorCountStat(errorStat);
    try {
        processor.serialize(null);
    } catch (Exception e) {
    // expected
    }
    /*
     * Verify start, stop are called, increment error count and never increment success count.
     */
    verify(runtimeStat, times(1)).start();
    verify(runtimeStat, times(1)).stop();
    verify(successStat, never()).increment();
    verify(errorStat, times(1)).increment();
}
Also used : DummySerializer(com.nextdoor.bender.testutils.DummySerializerHelper.DummySerializer) Stat(com.nextdoor.bender.monitoring.Stat) Test(org.junit.Test)

Example 3 with DummySerializer

use of com.nextdoor.bender.testutils.DummySerializerHelper.DummySerializer in project bender by Nextdoor.

the class SerializerProcessorTest method testStatsLogging.

@Test
public void testStatsLogging() throws SerializationException {
    DummySerializer serializer = new DummySerializer();
    SerializerProcessor processor = new SerializerProcessor(serializer);
    /*
     * Mock the Stat object
     */
    Stat runtimeStat = mock(Stat.class);
    Stat successStat = mock(Stat.class);
    Stat errorStat = mock(Stat.class);
    processor.setRuntimeStat(runtimeStat);
    processor.setSuccessCountStat(successStat);
    processor.setErrorCountStat(errorStat);
    processor.serialize("foo");
    /*
     * Verify start, stop, increment success count, and never increment error count.
     */
    verify(runtimeStat, times(1)).start();
    verify(runtimeStat, times(1)).stop();
    verify(successStat, times(1)).increment();
    verify(errorStat, never()).increment();
}
Also used : DummySerializer(com.nextdoor.bender.testutils.DummySerializerHelper.DummySerializer) Stat(com.nextdoor.bender.monitoring.Stat) Test(org.junit.Test)

Aggregations

Stat (com.nextdoor.bender.monitoring.Stat)3 DummySerializer (com.nextdoor.bender.testutils.DummySerializerHelper.DummySerializer)3 Test (org.junit.Test)3