use of org.apache.apex.malhar.lib.db.jdbc.JdbcNonTransactionalOutputOperatorTest.TestEvent in project apex-malhar by apache.
the class JdbcNonTransactionalBatchOutputOperatorTest method testAtLeastOnceHalfBatch.
@Test
public void testAtLeastOnceHalfBatch() {
JdbcOperatorTest.cleanTable();
Random random = new Random();
TestOutputOperator outputOperator = createOperator(ProcessingMode.AT_LEAST_ONCE);
outputOperator.beginWindow(0);
for (int batchCounter = 0; batchCounter < BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
outputOperator.endWindow();
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.beginWindow(1);
for (int batchCounter = 0; batchCounter < HALF_BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.getStore().disconnect();
// //
com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap attributeMap = new com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap();
attributeMap.put(OperatorContext.PROCESSING_MODE, ProcessingMode.AT_LEAST_ONCE);
attributeMap.put(OperatorContext.ACTIVATION_WINDOW_ID, 0L);
attributeMap.put(DAG.APPLICATION_ID, APP_ID);
OperatorContext context = mockOperatorContext(OPERATOR_ID, attributeMap);
outputOperator.setup(context);
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.beginWindow(0);
for (int batchCounter = 0; batchCounter < BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
outputOperator.endWindow();
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.beginWindow(1);
for (int batchCounter = 0; batchCounter < HALF_BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
outputOperator.endWindow();
Assert.assertEquals("Commit window id ", 1, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", 2 * BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
}
use of org.apache.apex.malhar.lib.db.jdbc.JdbcNonTransactionalOutputOperatorTest.TestEvent in project apex-malhar by apache.
the class JdbcNonTransactionalBatchOutputOperatorTest method testAtMostOnceHalfBatch.
@Test
public void testAtMostOnceHalfBatch() {
JdbcOperatorTest.cleanTable();
Random random = new Random();
TestOutputOperator outputOperator = createOperator(ProcessingMode.AT_MOST_ONCE);
outputOperator.beginWindow(0);
for (int batchCounter = 0; batchCounter < BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
outputOperator.endWindow();
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.beginWindow(1);
for (int batchCounter = 0; batchCounter < HALF_BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.getStore().disconnect();
// //
com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap attributeMap = new com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap();
attributeMap.put(OperatorContext.PROCESSING_MODE, ProcessingMode.AT_MOST_ONCE);
attributeMap.put(OperatorContext.ACTIVATION_WINDOW_ID, 0L);
attributeMap.put(DAG.APPLICATION_ID, APP_ID);
OperatorContext context = mockOperatorContext(OPERATOR_ID, attributeMap);
outputOperator.setup(context);
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.beginWindow(2);
for (int batchCounter = 0; batchCounter < BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
outputOperator.endWindow();
Assert.assertEquals("Commit window id ", 2, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", 2 * BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
}
use of org.apache.apex.malhar.lib.db.jdbc.JdbcNonTransactionalOutputOperatorTest.TestEvent in project apex-malhar by apache.
the class JdbcNonTransactionalBatchOutputOperatorTest method testAtMostOnceFullBatch.
@Test
public void testAtMostOnceFullBatch() {
JdbcOperatorTest.cleanTable();
Random random = new Random();
TestOutputOperator outputOperator = createOperator(ProcessingMode.AT_MOST_ONCE);
outputOperator.beginWindow(0);
for (int batchCounter = 0; batchCounter < BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
outputOperator.endWindow();
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.beginWindow(1);
for (int batchCounter = 0; batchCounter < BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", 2 * BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.getStore().disconnect();
// //
com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap attributeMap = new com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap();
attributeMap.put(OperatorContext.PROCESSING_MODE, ProcessingMode.AT_MOST_ONCE);
attributeMap.put(OperatorContext.ACTIVATION_WINDOW_ID, 0L);
attributeMap.put(DAG.APPLICATION_ID, APP_ID);
OperatorContext context = mockOperatorContext(OPERATOR_ID, attributeMap);
outputOperator.setup(context);
outputOperator.beginWindow(2);
for (int batchCounter = 0; batchCounter < BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
outputOperator.endWindow();
Assert.assertEquals("Commit window id ", 2, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", 3 * BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
}
use of org.apache.apex.malhar.lib.db.jdbc.JdbcNonTransactionalOutputOperatorTest.TestEvent in project apex-malhar by apache.
the class JdbcNonTransactionalBatchOutputOperatorTest method testBatch.
@Test
public void testBatch() {
JdbcOperatorTest.cleanTable();
Random random = new Random();
TestOutputOperator outputOperator = createOperator(ProcessingMode.AT_LEAST_ONCE);
outputOperator.beginWindow(0);
for (int batchCounter = 0; batchCounter < BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
outputOperator.endWindow();
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.beginWindow(1);
for (int batchCounter = 0; batchCounter < HALF_BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
outputOperator.endWindow();
Assert.assertEquals("Commit window id ", 1, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should not be written", BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.beginWindow(2);
for (int batchCounter = 0; batchCounter < HALF_BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
outputOperator.endWindow();
Assert.assertEquals("Commit window id ", 2, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should not be written", 2 * BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.teardown();
}
use of org.apache.apex.malhar.lib.db.jdbc.JdbcNonTransactionalOutputOperatorTest.TestEvent in project apex-malhar by apache.
the class JdbcNonTransactionalBatchOutputOperatorTest method testAtLeastOnceFullBatch.
@Test
public void testAtLeastOnceFullBatch() {
JdbcOperatorTest.cleanTable();
Random random = new Random();
TestOutputOperator outputOperator = createOperator(ProcessingMode.AT_LEAST_ONCE);
outputOperator.beginWindow(0);
for (int batchCounter = 0; batchCounter < BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
outputOperator.endWindow();
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.beginWindow(1);
for (int batchCounter = 0; batchCounter < BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", 2 * BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.getStore().disconnect();
// //
com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap attributeMap = new com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap();
attributeMap.put(OperatorContext.PROCESSING_MODE, ProcessingMode.AT_LEAST_ONCE);
attributeMap.put(OperatorContext.ACTIVATION_WINDOW_ID, 0L);
attributeMap.put(DAG.APPLICATION_ID, APP_ID);
OperatorContext context = mockOperatorContext(OPERATOR_ID, attributeMap);
outputOperator.setup(context);
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", 2 * BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.beginWindow(0);
for (int batchCounter = 0; batchCounter < BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
outputOperator.endWindow();
Assert.assertEquals("Commit window id ", 0, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", 2 * BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
outputOperator.beginWindow(1);
for (int batchCounter = 0; batchCounter < BATCH_SIZE; batchCounter++) {
outputOperator.input.put(new TestEvent(random.nextInt()));
}
outputOperator.endWindow();
Assert.assertEquals("Commit window id ", 1, outputOperator.getStore().getCommittedWindowId(APP_ID, OPERATOR_ID));
Assert.assertEquals("Batch should be written", 3 * BATCH_SIZE, outputOperator.getNumOfEventsInStore(outputOperator.getStore().connection));
}
Aggregations