Search in sources :

Example 1 with CouchbaseSource

use of org.talend.components.couchbase.runtime.CouchbaseSource in project components by Talend.

the class CouchbaseInputTestIT method testReader.

@Test
public void testReader() {
    populateBucket();
    Reader reader = null;
    try {
        CouchbaseInputDefinition definition = new CouchbaseInputDefinition();
        CouchbaseInputProperties properties = (CouchbaseInputProperties) definition.createRuntimeProperties();
        properties.bootstrapNodes.setValue(bootstrapNodes);
        properties.bucket.setValue(bucketName);
        properties.password.setValue(password);
        source = new CouchbaseSource();
        source.initialize(null, properties);
        reader = source.createReader(null);
        boolean hasRecords = reader.start();
        assertTrue(hasRecords);
        IndexedRecord row = (IndexedRecord) reader.getCurrent();
        assertNotNull(row);
        assertEquals("foo", row.get(EventSchemaField.KEY_IDX));
        assertEquals("{\"bar\":42}", new String(((byte[]) row.get(EventSchemaField.CONTENT_IDX))));
        reader.close();
    } catch (IOException e) {
        fail(e.getMessage());
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                fail(e.getMessage());
            }
        }
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) CouchbaseSource(org.talend.components.couchbase.runtime.CouchbaseSource) Reader(org.talend.components.api.component.runtime.Reader) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 Test (org.junit.Test)1 Reader (org.talend.components.api.component.runtime.Reader)1 CouchbaseSource (org.talend.components.couchbase.runtime.CouchbaseSource)1