Search in sources :

Example 41 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class TcpTransportBufferTest method clearShouldEmptyBuffer.

@Test
public void clearShouldEmptyBuffer() {
    TransportSerializer serializer = mock(TransportSerializer.class);
    TcpTransportBuffer buffer = new TcpTransportBuffer(10L, serializer);
    InternalEvent event = new InternalEvent("", null, 0);
    byte[] bytes = "foo".getBytes();
    when(serializer.serialize(eq(event))).thenReturn(bytes);
    assertTrue(buffer.add(event));
    assertEquals(bytes.length, buffer.getInternalBuffer().size());
    assertFalse(buffer.isEmpty());
    buffer.clear();
    assertEquals(0L, buffer.getInternalBuffer().size());
    assertTrue(buffer.isEmpty());
    assertTrue(buffer.add(event));
    assertEquals(bytes.length, buffer.getInternalBuffer().size());
    assertFalse(buffer.isEmpty());
}
Also used : TransportSerializer(com.nextdoor.bender.ipc.TransportSerializer) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 42 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class TimeOperationTest method testInvalidTime.

@Test(expected = OperationException.class)
public void testInvalidTime() {
    InternalEvent ievent = new InternalEvent("foo", null, 1);
    DummyDeserializedEvent devent = spy(new DummyDeserializedEvent(""));
    ievent.setEventObj(devent);
    doReturn("-1").when(devent).getField("foo");
    TimeOperation op = new TimeOperation("foo", TimeFieldType.SECONDS);
    op.perform(ievent);
}
Also used : DummyDeserializedEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializedEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 43 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class PartitionOperationTest method testGetEvaluatedPartitionsNoSuchElementException.

@Test
public void testGetEvaluatedPartitionsNoSuchElementException() {
    List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1);
    List<String> sources = Arrays.asList("one");
    PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING);
    partitionSpecs.add(spec);
    PartitionOperation op = new PartitionOperation(partitionSpecs);
    InternalEvent ievent = new InternalEvent("foo", null, 1);
    DummyDeserializedEvent devent = spy(new DummyDeserializedEvent("baz"));
    ievent.setEventObj(devent);
    doThrow(new NoSuchElementException()).when(devent).getField(any());
    op.perform(ievent);
    LinkedHashMap<String, String> actual = ievent.getPartitions();
    LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1);
    expected.put("foo", null);
    assertEquals(expected, actual);
}
Also used : DummyDeserializedEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializedEvent) ArrayList(java.util.ArrayList) NoSuchElementException(java.util.NoSuchElementException) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 44 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class PartitionOperationTest method testGetEvaluatedPartitionsStringMultipleFields.

@Test
public void testGetEvaluatedPartitionsStringMultipleFields() {
    List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1);
    List<String> sources = Arrays.asList("one", "two");
    PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING);
    partitionSpecs.add(spec);
    PartitionOperation op = new PartitionOperation(partitionSpecs);
    InternalEvent ievent = new InternalEvent("foo", null, 1);
    DummyDeserializedEvent devent = spy(new DummyDeserializedEvent(""));
    ievent.setEventObj(devent);
    doReturn(null).doReturn("5").when(devent).getField(any());
    op.perform(ievent);
    LinkedHashMap<String, String> actual = ievent.getPartitions();
    LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1);
    expected.put("foo", "5");
    assertEquals(expected, actual);
}
Also used : DummyDeserializedEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializedEvent) ArrayList(java.util.ArrayList) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 45 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class PartitionOperationTest method testGetEvaluatedPartitionsStringMultipleFieldsNull.

@Test
public void testGetEvaluatedPartitionsStringMultipleFieldsNull() {
    List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1);
    List<String> sources = Arrays.asList("one", "two");
    PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING);
    partitionSpecs.add(spec);
    PartitionOperation op = new PartitionOperation(partitionSpecs);
    InternalEvent ievent = new InternalEvent("foo", null, 1);
    DummyDeserializedEvent devent = spy(new DummyDeserializedEvent("baz"));
    ievent.setEventObj(devent);
    doReturn(null).doReturn(null).when(devent).getField(any());
    op.perform(ievent);
    LinkedHashMap<String, String> actual = ievent.getPartitions();
    LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1);
    expected.put("foo", null);
    assertEquals(expected, actual);
}
Also used : DummyDeserializedEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializedEvent) ArrayList(java.util.ArrayList) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

InternalEvent (com.nextdoor.bender.InternalEvent)68 Test (org.junit.Test)67 LinkedHashMap (java.util.LinkedHashMap)17 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)12 TestContext (com.nextdoor.bender.aws.TestContext)10 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)9 UploadPartRequest (com.amazonaws.services.s3.model.UploadPartRequest)9 DummyDeserializedEvent (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializedEvent)9 JsonElement (com.google.gson.JsonElement)7 JsonParser (com.google.gson.JsonParser)7 OperationTest (com.nextdoor.bender.operations.json.OperationTest)7 DummyOperationFactory (com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory)6 GenericTransportBuffer (com.nextdoor.bender.ipc.generic.GenericTransportBuffer)5 GenericTransportSerializer (com.nextdoor.bender.ipc.generic.GenericTransportSerializer)5 DummyOperation (com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperation)4 UploadPartResult (com.amazonaws.services.s3.model.UploadPartResult)3 Stat (com.nextdoor.bender.monitoring.Stat)3 KeyNameOperation (com.nextdoor.bender.operation.json.key.KeyNameOperation)3 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)3