Search in sources :

Example 6 with SequentialBasedBatchAccumulator

use of org.apache.gobblin.writer.SequentialBasedBatchAccumulator in project incubator-gobblin by apache.

the class EventhubAccumulatorTest method testClose.

@Test
public void testClose() throws IOException, InterruptedException {
    SequentialBasedBatchAccumulator accumulator = new EventhubBatchAccumulator(64, 3000, 5);
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 40; ++i) {
        buffer.append('a');
    }
    String record1 = buffer.toString() + "1";
    String record2 = buffer.toString() + "2";
    String record3 = buffer.toString() + "3";
    String record4 = buffer.toString() + "4";
    String record5 = buffer.toString() + "5";
    accumulator.append(record1, WriteCallback.EMPTY);
    accumulator.append(record2, WriteCallback.EMPTY);
    accumulator.append(record3, WriteCallback.EMPTY);
    accumulator.append(record4, WriteCallback.EMPTY);
    accumulator.append(record5, WriteCallback.EMPTY);
    (new Thread(new CloseAccumulatorThread(accumulator))).start();
    Thread.sleep(1000);
    Assert.assertEquals(accumulator.getNextAvailableBatch().getRecords().get(0), record1);
    Assert.assertEquals(accumulator.getNextAvailableBatch().getRecords().get(0), record2);
    Assert.assertEquals(accumulator.getNextAvailableBatch().getRecords().get(0), record3);
    Assert.assertEquals(accumulator.getNextAvailableBatch().getRecords().get(0), record4);
    Assert.assertEquals(accumulator.getNextAvailableBatch().getRecords().get(0), record5);
}
Also used : SequentialBasedBatchAccumulator(org.apache.gobblin.writer.SequentialBasedBatchAccumulator) Test(org.testng.annotations.Test)

Example 7 with SequentialBasedBatchAccumulator

use of org.apache.gobblin.writer.SequentialBasedBatchAccumulator in project incubator-gobblin by apache.

the class EventhubAccumulatorTest method testCloseAfterAwait.

@Test
public void testCloseAfterAwait() throws IOException, InterruptedException {
    SequentialBasedBatchAccumulator accumulator = new EventhubBatchAccumulator(64, 1000, 5);
    (new Thread(new CloseAccumulatorThread(accumulator))).start();
    // this thread should be blocked and waked up by spawned thread
    Assert.assertNull(accumulator.getNextAvailableBatch());
}
Also used : SequentialBasedBatchAccumulator(org.apache.gobblin.writer.SequentialBasedBatchAccumulator) Test(org.testng.annotations.Test)

Example 8 with SequentialBasedBatchAccumulator

use of org.apache.gobblin.writer.SequentialBasedBatchAccumulator in project incubator-gobblin by apache.

the class EventhubAccumulatorTest method testCloseBeforeAwait.

@Test
public void testCloseBeforeAwait() throws IOException, InterruptedException {
    SequentialBasedBatchAccumulator accumulator = new EventhubBatchAccumulator(64, 1000, 5);
    (new Thread(new CloseAccumulatorThread(accumulator))).start();
    Thread.sleep(1000);
    Assert.assertNull(accumulator.getNextAvailableBatch());
}
Also used : SequentialBasedBatchAccumulator(org.apache.gobblin.writer.SequentialBasedBatchAccumulator) Test(org.testng.annotations.Test)

Example 9 with SequentialBasedBatchAccumulator

use of org.apache.gobblin.writer.SequentialBasedBatchAccumulator in project incubator-gobblin by apache.

the class EventhubAccumulatorTest method testExpiredBatch.

@Test
public void testExpiredBatch() throws IOException, InterruptedException {
    SequentialBasedBatchAccumulator accumulator = new EventhubBatchAccumulator(64, 3000, 5);
    String record = "1";
    accumulator.append(record, WriteCallback.EMPTY);
    Assert.assertNull(accumulator.getNextAvailableBatch());
    Thread.sleep(3000);
    Assert.assertNotNull(accumulator.getNextAvailableBatch());
}
Also used : SequentialBasedBatchAccumulator(org.apache.gobblin.writer.SequentialBasedBatchAccumulator) Test(org.testng.annotations.Test)

Aggregations

SequentialBasedBatchAccumulator (org.apache.gobblin.writer.SequentialBasedBatchAccumulator)9 Test (org.testng.annotations.Test)7 Config (com.typesafe.config.Config)3 BatchAsyncDataWriter (org.apache.gobblin.writer.BatchAsyncDataWriter)3 BufferedAsyncDataWriter (org.apache.gobblin.writer.BufferedAsyncDataWriter)3 IOException (java.io.IOException)2 DataWriter (org.apache.gobblin.writer.DataWriter)2 GetRequest (org.elasticsearch.action.get.GetRequest)2 GetResponse (org.elasticsearch.action.get.GetResponse)2 JsonObject (com.google.gson.JsonObject)1 Properties (java.util.Properties)1 State (org.apache.gobblin.configuration.State)1 RecordTypeGenerator (org.apache.gobblin.test.RecordTypeGenerator)1