use of org.apache.bookkeeper.stream.proto.kv.rpc.ResponseOp in project bookkeeper by apache.
the class TableStoreImplTest method verifyVPutResponse.
KeyValue verifyVPutResponse(StorageContainerResponse response, boolean expectedSuccess) throws Exception {
assertEquals(ResponseCase.KV_TXN_RESP, response.getResponseCase());
TxnResponse txnResp = response.getKvTxnResp();
assertEquals(HEADER, txnResp.getHeader().getRoutingHeader());
assertEquals(StatusCode.SUCCESS, response.getCode());
ResponseOp respOp = txnResp.getResponses(0);
if (expectedSuccess) {
assertTrue(txnResp.getSucceeded());
PutResponse putResp = respOp.getResponsePut();
assertEquals(HEADER, putResp.getHeader().getRoutingHeader());
if (!putResp.hasPrevKv()) {
return null;
}
return putResp.getPrevKv();
} else {
assertFalse(txnResp.getSucceeded());
RangeResponse rangeResp = respOp.getResponseRange();
if (rangeResp.getCount() == 0) {
return null;
} else {
assertEquals(1, rangeResp.getCount());
return rangeResp.getKvs(0);
}
}
}
use of org.apache.bookkeeper.stream.proto.kv.rpc.ResponseOp in project bookkeeper by apache.
the class TableStoreImplTest method putIfAbsentToTableStore.
KeyValue putIfAbsentToTableStore(int key, int value, boolean expectedSuccess) throws Exception {
StorageContainerResponse response = result(tableStore.txn(StorageContainerRequest.newBuilder().setScId(SC_ID).setKvTxnReq(TxnRequest.newBuilder().setHeader(HEADER).addCompare(Compare.newBuilder().setResult(CompareResult.EQUAL).setTarget(CompareTarget.VALUE).setKey(getKey(key)).setValue(ByteString.copyFrom(new byte[0]))).addSuccess(RequestOp.newBuilder().setRequestPut(PutRequest.newBuilder().setHeader(HEADER).setKey(getKey(key)).setValue(getValue(value)).setPrevKv(true).build())).addFailure(RequestOp.newBuilder().setRequestRange(RangeRequest.newBuilder().setHeader(HEADER).setKey(getKey(key)).build())).build()).build()));
assertEquals(ResponseCase.KV_TXN_RESP, response.getResponseCase());
TxnResponse txnResp = response.getKvTxnResp();
assertEquals(HEADER, txnResp.getHeader().getRoutingHeader());
assertEquals(StatusCode.SUCCESS, response.getCode());
ResponseOp respOp = txnResp.getResponses(0);
if (expectedSuccess) {
assertTrue(txnResp.getSucceeded());
PutResponse putResp = respOp.getResponsePut();
assertEquals(HEADER, putResp.getHeader().getRoutingHeader());
if (!putResp.hasPrevKv()) {
return null;
}
return putResp.getPrevKv();
} else {
assertFalse(txnResp.getSucceeded());
RangeResponse rangeResp = respOp.getResponseRange();
if (rangeResp.getCount() == 0) {
return null;
} else {
assertEquals(1, rangeResp.getCount());
return rangeResp.getKvs(0);
}
}
}
Aggregations