Search in sources :

Example 11 with ByteBuf

use of com.couchbase.client.deps.io.netty.buffer.ByteBuf in project components by Talend.

the class CouchbaseEventGenericRecordConverterTest method testConvertToAvroFailedIllegalRecordIndex.

@Test(expected = IndexOutOfBoundsException.class)
public void testConvertToAvroFailedIllegalRecordIndex() {
    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);
    record.get(10);
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) ByteBuf(com.couchbase.client.deps.io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 12 with ByteBuf

use of com.couchbase.client.deps.io.netty.buffer.ByteBuf in project components by Talend.

the class CouchbaseEventGenericRecordConverterTest method testConvertToAvroFailedToChangeRecord.

@Test(expected = UnmodifiableAdapterException.class)
public void testConvertToAvroFailedToChangeRecord() {
    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);
    record.put(0, "Update is not supported");
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) ByteBuf(com.couchbase.client.deps.io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

ByteBuf (com.couchbase.client.deps.io.netty.buffer.ByteBuf)12 Test (org.junit.Test)8 IndexedRecord (org.apache.avro.generic.IndexedRecord)5 SessionState (com.couchbase.client.dcp.state.SessionState)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 CouchbaseException (com.couchbase.client.core.CouchbaseException)1 Bucket (com.couchbase.client.java.Bucket)1 PersistTo (com.couchbase.client.java.PersistTo)1 ReplicateTo (com.couchbase.client.java.ReplicateTo)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 SingleRecordIterable (org.apache.gobblin.converter.SingleRecordIterable)1 TupleDocument (org.apache.gobblin.couchbase.common.TupleDocument)1 FlowFile (org.apache.nifi.flowfile.FlowFile)1 ComponentLog (org.apache.nifi.logging.ComponentLog)1