Search in sources :

Example 1 with PutResponse

use of org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse in project bookkeeper by apache.

the class TableStoreUtils method processPutResult.

static PutResponse processPutResult(RoutingHeader routingHeader, PutResult<byte[], byte[]> result) {
    ByteString rKey = routingHeader.getRKey();
    PutResponse.Builder putRespBuilder = PutResponse.newBuilder().setHeader(ResponseHeader.newBuilder().setRoutingHeader(routingHeader).build());
    if (null != result.prevKv()) {
        putRespBuilder = putRespBuilder.setPrevKv(newKeyValue(rKey, result.prevKv()));
    }
    return putRespBuilder.build();
}
Also used : ByteString(com.google.protobuf.ByteString) PutResponse(org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse)

Example 2 with PutResponse

use of org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse in project bookkeeper by apache.

the class TableStoreImplTest method putKeyToTableStore.

void putKeyToTableStore(int key, int value) throws Exception {
    StorageContainerResponse response = result(tableStore.put(StorageContainerRequest.newBuilder().setScId(SC_ID).setKvPutReq(PutRequest.newBuilder().setHeader(HEADER).setKey(getKey(key)).setValue(getValue(value)).build()).build()));
    assertEquals(StatusCode.SUCCESS, response.getCode());
    assertEquals(ResponseCase.KV_PUT_RESP, response.getResponseCase());
    PutResponse putResp = response.getKvPutResp();
    assertEquals(HEADER, putResp.getHeader().getRoutingHeader());
    assertFalse(putResp.hasPrevKv());
}
Also used : PutResponse(org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)

Example 3 with PutResponse

use of org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse in project bookkeeper by apache.

the class TableStoreImplTest method writeKVs.

private List<KeyValue> writeKVs(int numPairs, boolean prevKv) throws Exception {
    List<CompletableFuture<StorageContainerResponse>> results = Lists.newArrayListWithExpectedSize(numPairs);
    for (int i = 0; i < numPairs; i++) {
        results.add(writeKV(i, prevKv));
    }
    return Lists.transform(result(FutureUtils.collect(results)), response -> {
        assertEquals(StatusCode.SUCCESS, response.getCode());
        assertEquals(ResponseCase.KV_PUT_RESP, response.getResponseCase());
        PutResponse putResp = response.getKvPutResp();
        assertEquals(HEADER, putResp.getHeader().getRoutingHeader());
        if (putResp.hasPrevKv()) {
            return putResp.getPrevKv();
        } else {
            return null;
        }
    });
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) PutResponse(org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse)

Example 4 with PutResponse

use of org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse 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);
        }
    }
}
Also used : DeleteRangeResponse(org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeResponse) RangeResponse(org.apache.bookkeeper.stream.proto.kv.rpc.RangeResponse) ResponseOp(org.apache.bookkeeper.stream.proto.kv.rpc.ResponseOp) TxnResponse(org.apache.bookkeeper.stream.proto.kv.rpc.TxnResponse) PutResponse(org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse)

Example 5 with PutResponse

use of org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse 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);
        }
    }
}
Also used : DeleteRangeResponse(org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeResponse) RangeResponse(org.apache.bookkeeper.stream.proto.kv.rpc.RangeResponse) ResponseOp(org.apache.bookkeeper.stream.proto.kv.rpc.ResponseOp) TxnResponse(org.apache.bookkeeper.stream.proto.kv.rpc.TxnResponse) PutResponse(org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)

Aggregations

PutResponse (org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse)5 DeleteRangeResponse (org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeResponse)2 RangeResponse (org.apache.bookkeeper.stream.proto.kv.rpc.RangeResponse)2 ResponseOp (org.apache.bookkeeper.stream.proto.kv.rpc.ResponseOp)2 TxnResponse (org.apache.bookkeeper.stream.proto.kv.rpc.TxnResponse)2 StorageContainerResponse (org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)2 ByteString (com.google.protobuf.ByteString)1 CompletableFuture (java.util.concurrent.CompletableFuture)1