Search in sources :

Example 1 with RecordTypeGenerator

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();
            }
        }
    }
}
Also used : Config(com.typesafe.config.Config) BufferedAsyncDataWriter(org.apache.gobblin.writer.BufferedAsyncDataWriter) SequentialBasedBatchAccumulator(org.apache.gobblin.writer.SequentialBasedBatchAccumulator) GetResponse(org.elasticsearch.action.get.GetResponse) IOException(java.io.IOException) GetRequest(org.elasticsearch.action.get.GetRequest) RecordTypeGenerator(org.apache.gobblin.test.RecordTypeGenerator) DataWriter(org.apache.gobblin.writer.DataWriter) BufferedAsyncDataWriter(org.apache.gobblin.writer.BufferedAsyncDataWriter) BatchAsyncDataWriter(org.apache.gobblin.writer.BatchAsyncDataWriter) Test(org.testng.annotations.Test)

Aggregations

Config (com.typesafe.config.Config)1 IOException (java.io.IOException)1 RecordTypeGenerator (org.apache.gobblin.test.RecordTypeGenerator)1 BatchAsyncDataWriter (org.apache.gobblin.writer.BatchAsyncDataWriter)1 BufferedAsyncDataWriter (org.apache.gobblin.writer.BufferedAsyncDataWriter)1 DataWriter (org.apache.gobblin.writer.DataWriter)1 SequentialBasedBatchAccumulator (org.apache.gobblin.writer.SequentialBasedBatchAccumulator)1 GetRequest (org.elasticsearch.action.get.GetRequest)1 GetResponse (org.elasticsearch.action.get.GetResponse)1 Test (org.testng.annotations.Test)1