use of com.couchbase.client.core.message.dcp.DCPRequest in project asterixdb by apache.
the class DCPMessageToRecordConverter method convert.
@Override
public RecordWithMetadataAndPK<char[]> convert(final IRawRecord<? extends DCPRequest> input) throws IOException {
final DCPRequest dcpRequest = input.get();
if (dcpRequest instanceof MutationMessage) {
final MutationMessage message = (MutationMessage) dcpRequest;
try {
final String key = message.key();
final int vbucket = message.partition();
final long seq = message.bySequenceNumber();
final long cas = message.cas();
final int expiration = message.expiration();
final int flags = message.flags();
final long revSeqNumber = message.revisionSequenceNumber();
final int lockTime = message.lockTime();
int i = 0;
recordWithMetadata.reset();
recordWithMetadata.setMetadata(i++, key);
recordWithMetadata.setMetadata(i++, vbucket);
recordWithMetadata.setMetadata(i++, seq);
recordWithMetadata.setMetadata(i++, cas);
recordWithMetadata.setMetadata(i++, expiration);
recordWithMetadata.setMetadata(i++, flags);
recordWithMetadata.setMetadata(i++, revSeqNumber);
recordWithMetadata.setMetadata(i, lockTime);
DCPMessageToRecordConverter.set(message.content(), decoder, bytes, chars, value);
} finally {
ReferenceCountUtil.release(message.content());
}
} else if (dcpRequest instanceof RemoveMessage) {
final RemoveMessage message = (RemoveMessage) dcpRequest;
final String key = message.key();
recordWithMetadata.reset();
recordWithMetadata.setMetadata(0, key);
} else {
throw new RuntimeDataException(ErrorCode.INPUT_RECORD_CONVERTER_DCP_MSG_TO_RECORD_CONVERTER_UNKNOWN_DCP_REQUEST, dcpRequest.toString());
}
return recordWithMetadata;
}
use of com.couchbase.client.core.message.dcp.DCPRequest in project asterixdb by apache.
the class DCPGeneratorTest method runTest.
@Test
public void runTest() throws Exception {
try (KVTestReader cbreader = new KVTestReader(0, "TestBucket", new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 150, 0, 0, 0)) {
final UTF8StringPointable pointable = new UTF8StringPointable();
final DCPMessageToRecordConverter converter = new DCPMessageToRecordConverter();
while (cbreader.hasNext()) {
final IRawRecord<DCPRequest> dcp = cbreader.next();
final RecordWithMetadataAndPK<char[]> record = converter.convert(dcp);
if (record.getRecord().size() == 0) {
pointable.set(record.getMetadata(0).getByteArray(), 1, record.getMetadata(0).getLength());
} else {
pointable.set(record.getMetadata(0).getByteArray(), 1, record.getMetadata(0).getLength());
}
}
} catch (final Throwable th) {
System.err.println("TEST FAILED");
th.printStackTrace();
throw th;
}
System.err.println("TEST PASSED.");
}
use of com.couchbase.client.core.message.dcp.DCPRequest in project asterixdb by apache.
the class KVTestReader method next.
@Override
public IRawRecord<DCPRequest> next() throws IOException, InterruptedException {
if (stopped) {
return null;
}
try {
final DCPRequest dcpRequest = generateNextDCPMessage();
record.set(dcpRequest);
if (counter >= numberOfMutations) {
stop();
}
} catch (final Throwable th) {
LOGGER.error(th.getMessage(), th);
}
return record;
}
Aggregations