use of com.google.appengine.api.memcache.MemcacheServicePb.MemcacheBatchIncrementResponse 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);
}
Aggregations