Search in sources :

Example 36 with StorageContainerResponse

use of org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse 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)

Example 37 with StorageContainerResponse

use of org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse in project bookkeeper by apache.

the class MetaRangeStoreImplTest method testCreateIfMissingPropsNotSpecified.

@Test
public void testCreateIfMissingPropsNotSpecified() throws Exception {
    StorageContainerResponse resp = FutureUtils.result(this.mrStoreImpl.getActiveRanges(createRequest(null)));
    assertEquals(StatusCode.STREAM_NOT_FOUND, resp.getCode());
}
Also used : StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 38 with StorageContainerResponse

use of org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse in project bookkeeper by apache.

the class StorageContainerImplTest method testPutWhenTableStoreCached.

@Test
public void testPutWhenTableStoreCached() throws Exception {
    mockStorageContainer(SCID);
    StorageContainerResponse expectedResp = StorageContainerResponse.getDefaultInstance();
    when(trStore.put(any(StorageContainerRequest.class))).thenReturn(FutureUtils.value(expectedResp));
    container.getTableStoreCache().getTableStores().put(RID, trStore);
    StorageContainerRequest request = newStorageContainerRequest(KV_PUT_REQ);
    StorageContainerResponse response = FutureUtils.result(container.put(request));
    assertSame(expectedResp, response);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 39 with StorageContainerResponse

use of org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse in project bookkeeper by apache.

the class StorageContainerImplTest method testRangeWhenTableStoreCached.

@Test
public void testRangeWhenTableStoreCached() throws Exception {
    mockStorageContainer(SCID);
    StorageContainerResponse expectedResp = StorageContainerResponse.getDefaultInstance();
    when(trStore.range(any(StorageContainerRequest.class))).thenReturn(FutureUtils.value(expectedResp));
    container.getTableStoreCache().getTableStores().put(RID, trStore);
    StorageContainerRequest request = newStorageContainerRequest(KV_RANGE_REQ);
    StorageContainerResponse response = FutureUtils.result(container.range(request));
    assertSame(expectedResp, response);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 40 with StorageContainerResponse

use of org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse in project bookkeeper by apache.

the class StorageContainerImplTest method testTxnWhenTableStoreCached.

@Test
public void testTxnWhenTableStoreCached() throws Exception {
    mockStorageContainer(SCID);
    StorageContainerResponse expectedResp = StorageContainerResponse.getDefaultInstance();
    when(trStore.txn(any(StorageContainerRequest.class))).thenReturn(FutureUtils.value(expectedResp));
    container.getTableStoreCache().getTableStores().put(RID, trStore);
    StorageContainerRequest request = newStorageContainerRequest(KV_TXN_REQ);
    StorageContainerResponse response = FutureUtils.result(container.txn(request));
    assertSame(expectedResp, response);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Aggregations

StorageContainerResponse (org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)42 Test (org.junit.Test)33 StorageContainerRequest (org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest)27 TestResponseObserver (org.apache.bookkeeper.stream.server.TestResponseObserver)12 RangeStore (org.apache.bookkeeper.stream.storage.api.RangeStore)9 StatusRuntimeException (io.grpc.StatusRuntimeException)6 DeleteRangeResponse (org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeResponse)5 StorageContainer (org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)4 StreamObserver (io.grpc.stub.StreamObserver)3 RangeResponse (org.apache.bookkeeper.stream.proto.kv.rpc.RangeResponse)3 GetActiveRangesResponse (org.apache.bookkeeper.stream.proto.storage.GetActiveRangesResponse)3 RangeStoreImpl (org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl)3 StatusException (io.grpc.StatusException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)2 PutResponse (org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse)2 Status (io.grpc.Status)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Cleanup (lombok.Cleanup)1