use of com.couchbase.client.deps.io.netty.buffer.ByteBuf in project incubator-gobblin by apache.
the class AvroToCouchbaseTupleConverter method convertRecord.
@Override
public Iterable<TupleDocument> convertRecord(String outputSchema, GenericRecord inputRecord, WorkUnitState workUnit) throws DataConversionException {
String key = inputRecord.get(keyField).toString();
GenericRecord data = (GenericRecord) inputRecord.get(dataRecordField);
ByteBuffer dataBytes = (ByteBuffer) data.get(valueField);
Integer flags = (Integer) data.get(flagsField);
ByteBuf buffer = Unpooled.copiedBuffer(dataBytes);
return new SingleRecordIterable<>(new TupleDocument(key, Tuple.create(buffer, flags)));
}
use of com.couchbase.client.deps.io.netty.buffer.ByteBuf in project components by Talend.
the class CouchbaseStreamingConnectionTest method testStartStopStreaming.
@Test
public void testStartStopStreaming() throws InterruptedException {
Mockito.when(client.initializeState(StreamFrom.BEGINNING, StreamTo.NOW)).thenReturn(Completable.complete());
Mockito.when(client.startStreaming(Mockito.<Short[]>anyVararg())).thenReturn(Completable.complete());
Mockito.when(client.stopStreaming(Mockito.<Short[]>anyVararg())).thenReturn(Completable.complete());
SessionState sessionState = Mockito.mock(SessionState.class);
Mockito.when(sessionState.isAtEnd()).thenReturn(false, true);
Mockito.when(client.sessionState()).thenReturn(sessionState);
BlockingQueue<ByteBuf> resultsQueue = new ArrayBlockingQueue<>(4);
resultsQueue.put(Mockito.mock(ByteBuf.class));
resultsQueue.put(Mockito.mock(ByteBuf.class));
resultsQueue.put(Mockito.mock(ByteBuf.class));
resultsQueue.put(Mockito.mock(ByteBuf.class));
Mockito.when(client.disconnect()).thenReturn(Completable.complete());
streamingConnection.startStreaming(resultsQueue);
streamingConnection.stopStreaming();
Thread.sleep(1500);
Mockito.verify(client, Mockito.times(2)).sessionState();
Mockito.verify(client, Mockito.times(1)).disconnect();
}
use of com.couchbase.client.deps.io.netty.buffer.ByteBuf in project components by Talend.
the class CouchbaseReader method advance.
@Override
public boolean advance() throws IOException {
while (true) {
ByteBuf event;
try {
event = resultsQueue.poll(1, TimeUnit.SECONDS);
} catch (InterruptedException e) {
LOG.error("Failed to poll event from the results queue", e);
return false;
}
if (event != null) {
currentRecord = converter.convertToAvro(event);
connection.acknowledge(event);
event.release();
recordCount++;
return true;
}
if (!connection.isStreaming() && resultsQueue.isEmpty()) {
break;
}
}
return false;
}
use of com.couchbase.client.deps.io.netty.buffer.ByteBuf in project components by Talend.
the class CouchbaseEventGenericRecordConverterTest method testConvertToAvroMutation.
@Test
public void testConvertToAvroMutation() {
ByteBuf buffer = Mockito.mock(ByteBuf.class);
// Mocking key object
Mockito.when(buffer.getByte(0)).thenReturn(MessageUtil.MAGIC_REQ);
Mockito.when(buffer.getByte(1)).thenReturn(MessageUtil.DCP_MUTATION_OPCODE);
Mockito.when(buffer.getByte(4)).thenReturn(OFFSET);
Mockito.when(buffer.getShort(2)).thenReturn(LENGTH);
ByteBuf key = Mockito.mock(ByteBuf.class);
Mockito.when(key.readableBytes()).thenReturn(4);
Mockito.when(buffer.slice(29, 10)).thenReturn(key);
// Mocking content object.
Mockito.when(buffer.getByte(4)).thenReturn(OFFSET);
Mockito.when(buffer.getShort(2)).thenReturn(LENGTH);
Mockito.when(buffer.getInt(8)).thenReturn(100);
ByteBuf content = Mockito.mock(ByteBuf.class);
// Content byte array length.
Mockito.when(content.readableBytes()).thenReturn(85);
Mockito.when(buffer.slice(39, 85)).thenReturn(content);
IndexedRecord record = converter.convertToAvro(buffer);
Assert.assertEquals(schema, record.getSchema());
assertIndexedRecordResult(record, "mutation", new byte[85]);
}
use of com.couchbase.client.deps.io.netty.buffer.ByteBuf in project components by Talend.
the class CouchbaseEventGenericRecordConverterTest method testConvertToAvroExpiration.
@Test
public void testConvertToAvroExpiration() {
ByteBuf buffer = Mockito.mock(ByteBuf.class);
// Mocking key object
Mockito.when(buffer.getByte(0)).thenReturn(MessageUtil.MAGIC_REQ);
Mockito.when(buffer.getByte(1)).thenReturn(MessageUtil.DCP_EXPIRATION_OPCODE);
Mockito.when(buffer.getByte(4)).thenReturn(OFFSET);
Mockito.when(buffer.getShort(2)).thenReturn(LENGTH);
ByteBuf key = Mockito.mock(ByteBuf.class);
Mockito.when(key.readableBytes()).thenReturn(4);
Mockito.when(buffer.slice(29, 10)).thenReturn(key);
IndexedRecord record = converter.convertToAvro(buffer);
assertIndexedRecordResult(record, "expiration", null);
}
Aggregations