Search in sources :

Example 6 with MemcacheBatchIncrementRequest

use of com.google.appengine.api.memcache.MemcacheServicePb.MemcacheBatchIncrementRequest in project appengine-java-standard by GoogleCloudPlatform.

the class MemcacheServiceImplTest method testIncrementAll.

@Test
public void testIncrementAll() {
    MemcacheBatchIncrementRequest.Builder batchRequestBuilder = MemcacheBatchIncrementRequest.newBuilder().setNameSpace("hi");
    batchRequestBuilder.addItem(MemcacheIncrementRequest.newBuilder().setKey(ByteString.copyFrom(makePbKey("my key 1"))).setDirection(MemcacheIncrementRequest.Direction.INCREMENT).setDelta(22));
    batchRequestBuilder.addItem(MemcacheIncrementRequest.newBuilder().setKey(ByteString.copyFrom(makePbKey("my key 2"))).setDirection(MemcacheIncrementRequest.Direction.INCREMENT).setDelta(22));
    batchRequestBuilder.addItem(MemcacheIncrementRequest.newBuilder().setKey(ByteString.copyFrom(makePbKey("my key 3"))).setDirection(MemcacheIncrementRequest.Direction.INCREMENT).setDelta(22));
    MemcacheBatchIncrementResponse.Builder responseBuilder = MemcacheBatchIncrementResponse.newBuilder();
    responseBuilder.addItem(MemcacheIncrementResponse.newBuilder().setNewValue(123).setIncrementStatus(IncrementStatusCode.OK));
    responseBuilder.addItem(MemcacheIncrementResponse.newBuilder().setIncrementStatus(IncrementStatusCode.NOT_CHANGED));
    responseBuilder.addItem(MemcacheIncrementResponse.newBuilder().setIncrementStatus(IncrementStatusCode.ERROR));
    MemcacheBatchIncrementRequest request = batchRequestBuilder.build();
    MemcacheBatchIncrementResponse response = responseBuilder.build();
    expectAsyncCall("BatchIncrement", request, response);
    ArrayList<String> keys = new ArrayList<>();
    keys.add("my key 1");
    keys.add("my key 2");
    keys.add("my key 3");
    Map<String, Long> expected = new LinkedHashMap<>();
    expected.put("my key 1", 123L);
    expected.put("my key 2", null);
    expected.put("my key 3", null);
    MemcacheService memcache = new MemcacheServiceImpl("hi");
    assertThat(memcache.incrementAll(keys, 22L)).isEqualTo(expected);
    verifyAsyncCall("BatchIncrement", request);
}
Also used : MemcacheBatchIncrementResponse(com.google.appengine.api.memcache.MemcacheServicePb.MemcacheBatchIncrementResponse) ArrayList(java.util.ArrayList) MemcacheBatchIncrementRequest(com.google.appengine.api.memcache.MemcacheServicePb.MemcacheBatchIncrementRequest) ByteString(com.google.protobuf.ByteString) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 7 with MemcacheBatchIncrementRequest

use of com.google.appengine.api.memcache.MemcacheServicePb.MemcacheBatchIncrementRequest in project appengine-java-standard by GoogleCloudPlatform.

the class MemcacheServiceImplTest method testIncrementAllFailed.

@Test
public void testIncrementAllFailed() {
    MemcacheBatchIncrementRequest.Builder batchRequestBuilder = MemcacheBatchIncrementRequest.newBuilder().setNameSpace("hi");
    batchRequestBuilder.addItem(MemcacheIncrementRequest.newBuilder().setKey(ByteString.copyFrom(makePbKey("my key 1"))).setDirection(MemcacheIncrementRequest.Direction.INCREMENT).setDelta(22));
    batchRequestBuilder.addItem(MemcacheIncrementRequest.newBuilder().setKey(ByteString.copyFrom(makePbKey("my key 2"))).setDirection(MemcacheIncrementRequest.Direction.INCREMENT).setDelta(22));
    batchRequestBuilder.addItem(MemcacheIncrementRequest.newBuilder().setKey(ByteString.copyFrom(makePbKey("my key 3"))).setDirection(MemcacheIncrementRequest.Direction.INCREMENT).setDelta(22));
    MemcacheBatchIncrementRequest request = batchRequestBuilder.build();
    expectAsyncCall("BatchIncrement", request, new ApiProxy.ApplicationException(1, "Error"));
    ArrayList<String> keys = new ArrayList<>();
    keys.add("my key 1");
    keys.add("my key 2");
    keys.add("my key 3");
    Map<String, Long> expected = new LinkedHashMap<>();
    expected.put("my key 1", null);
    expected.put("my key 2", null);
    expected.put("my key 3", null);
    MemcacheService memcache = new MemcacheServiceImpl("hi");
    assertThat(memcache.incrementAll(keys, 22L)).isEqualTo(expected);
}
Also used : ApiProxy(com.google.apphosting.api.ApiProxy) ArrayList(java.util.ArrayList) MemcacheBatchIncrementRequest(com.google.appengine.api.memcache.MemcacheServicePb.MemcacheBatchIncrementRequest) ByteString(com.google.protobuf.ByteString) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 8 with MemcacheBatchIncrementRequest

use of com.google.appengine.api.memcache.MemcacheServicePb.MemcacheBatchIncrementRequest in project appengine-java-standard by GoogleCloudPlatform.

the class MemcacheServiceImplTest method testIncrementAllKeysWithInitialValue.

@Test
public void testIncrementAllKeysWithInitialValue() {
    MemcacheBatchIncrementRequest.Builder batchRequestBuilder = MemcacheBatchIncrementRequest.newBuilder().setNameSpace("hi");
    batchRequestBuilder.addItem(MemcacheIncrementRequest.newBuilder().setKey(ByteString.copyFrom(makePbKey("my key 1"))).setDirection(MemcacheIncrementRequest.Direction.INCREMENT).setInitialValue(44).setInitialFlags(MemcacheSerialization.Flag.LONG.ordinal()).setDelta(22));
    batchRequestBuilder.addItem(MemcacheIncrementRequest.newBuilder().setKey(ByteString.copyFrom(makePbKey("my key 2"))).setDirection(MemcacheIncrementRequest.Direction.INCREMENT).setInitialValue(44).setInitialFlags(MemcacheSerialization.Flag.LONG.ordinal()).setDelta(22));
    batchRequestBuilder.addItem(MemcacheIncrementRequest.newBuilder().setKey(ByteString.copyFrom(makePbKey("my key 3"))).setDirection(MemcacheIncrementRequest.Direction.INCREMENT).setInitialValue(44).setInitialFlags(MemcacheSerialization.Flag.LONG.ordinal()).setDelta(22));
    MemcacheBatchIncrementResponse.Builder responseBuilder = MemcacheBatchIncrementResponse.newBuilder();
    responseBuilder.addItem(MemcacheIncrementResponse.newBuilder().setNewValue(123).setIncrementStatus(IncrementStatusCode.OK));
    responseBuilder.addItem(MemcacheIncrementResponse.newBuilder().setIncrementStatus(IncrementStatusCode.NOT_CHANGED));
    responseBuilder.addItem(MemcacheIncrementResponse.newBuilder().setIncrementStatus(IncrementStatusCode.ERROR));
    MemcacheBatchIncrementRequest request = batchRequestBuilder.build();
    MemcacheBatchIncrementResponse response = responseBuilder.build();
    expectAsyncCall("BatchIncrement", request, response);
    ArrayList<String> keys = new ArrayList<>();
    keys.add("my key 1");
    keys.add("my key 2");
    keys.add("my key 3");
    Map<String, Long> expected = new LinkedHashMap<>();
    expected.put("my key 1", 123L);
    expected.put("my key 2", null);
    expected.put("my key 3", null);
    MemcacheService memcache = new MemcacheServiceImpl("hi");
    assertThat(memcache.incrementAll(keys, 22L, 44L)).isEqualTo(expected);
    verifyAsyncCall("BatchIncrement", request);
}
Also used : MemcacheBatchIncrementResponse(com.google.appengine.api.memcache.MemcacheServicePb.MemcacheBatchIncrementResponse) ArrayList(java.util.ArrayList) MemcacheBatchIncrementRequest(com.google.appengine.api.memcache.MemcacheServicePb.MemcacheBatchIncrementRequest) ByteString(com.google.protobuf.ByteString) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

MemcacheBatchIncrementRequest (com.google.appengine.api.memcache.MemcacheServicePb.MemcacheBatchIncrementRequest)8 Test (org.junit.Test)7 LinkedHashMap (java.util.LinkedHashMap)6 MemcacheBatchIncrementResponse (com.google.appengine.api.memcache.MemcacheServicePb.MemcacheBatchIncrementResponse)5 ByteString (com.google.protobuf.ByteString)5 ArrayList (java.util.ArrayList)4 ApiProxy (com.google.apphosting.api.ApiProxy)3 MemcacheDeleteRequest (com.google.appengine.api.memcache.MemcacheServicePb.MemcacheDeleteRequest)2 MemcacheFlushRequest (com.google.appengine.api.memcache.MemcacheServicePb.MemcacheFlushRequest)2 MemcacheGetRequest (com.google.appengine.api.memcache.MemcacheServicePb.MemcacheGetRequest)2 MemcacheIncrementRequest (com.google.appengine.api.memcache.MemcacheServicePb.MemcacheIncrementRequest)2 MemcacheSetRequest (com.google.appengine.api.memcache.MemcacheServicePb.MemcacheSetRequest)2