use of org.apache.gobblin.test.RecordTypeGenerator in project incubator-gobblin by apache.
the class ElasticsearchWriterIntegrationTest method testSingleRecordWrite.
@Test
public void testSingleRecordWrite() throws IOException {
for (WriterVariant writerVariant : variants) {
for (RecordTypeGenerator recordVariant : recordGenerators) {
String indexName = "posts" + writerVariant.getName().toLowerCase();
String indexType = recordVariant.getName();
Config config = writerVariant.getConfigBuilder().setIndexName(indexName).setIndexType(indexType).setTypeMapperClassName(recordVariant.getTypeMapperClassName()).setHttpPort(_esTestServer.getHttpPort()).setTransportPort(_esTestServer.getTransportPort()).build();
TestClient testClient = writerVariant.getTestClient(config);
SequentialBasedBatchAccumulator<Object> batchAccumulator = new SequentialBasedBatchAccumulator<>(config);
BufferedAsyncDataWriter bufferedAsyncDataWriter = new BufferedAsyncDataWriter(batchAccumulator, writerVariant.getBatchAsyncDataWriter(config));
String id = TestUtils.generateRandomAlphaString(10);
Object testRecord = recordVariant.getRecord(id, PayloadType.STRING);
DataWriter writer = AsyncWriterManager.builder().failureAllowanceRatio(0.0).retriesEnabled(false).config(config).asyncDataWriter(bufferedAsyncDataWriter).build();
try {
testClient.recreateIndex(indexName);
writer.write(testRecord);
writer.commit();
} finally {
writer.close();
}
try {
GetResponse response = testClient.get(new GetRequest(indexName, indexType, id));
Assert.assertEquals(response.getId(), id, "Response id matches request");
Assert.assertEquals(response.isExists(), true, "Document not found");
} catch (Exception e) {
Assert.fail("Failed to get a response", e);
} finally {
testClient.close();
}
}
}
}
Aggregations