Search in sources :

Example 1 with MemcacheDeleteResponse

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

the class LocalMemcacheService method delete.

@LatencyPercentiles(latency50th = 4)
public MemcacheDeleteResponse delete(Status status, MemcacheDeleteRequest req) {
    MemcacheDeleteResponse.Builder result = MemcacheDeleteResponse.newBuilder();
    final String namespace = req.getNameSpace();
    for (int i = 0; i < req.getItemCount(); i++) {
        MemcacheDeleteRequest.Item item = req.getItem(i);
        Key key = new Key(item.getKey().toByteArray());
        CacheEntry ce = internalDelete(namespace, key);
        result.addDeleteStatus(ce == null ? DeleteStatusCode.NOT_FOUND : DeleteStatusCode.DELETED);
        if (ce != null) {
            stats.recordDelete(ce);
        }
        // open spec whether this happens if there was no deletion
        if (item.hasDeleteTime()) {
            int millisNoReAdd = item.getDeleteTime() * 1000;
            getOrMakeSubMap(deleteHold, namespace).put(key, clock.getCurrentTime() + millisNoReAdd);
        }
    }
    status.setSuccessful(true);
    return result.build();
}
Also used : MemcacheDeleteResponse(com.google.appengine.api.memcache.MemcacheServicePb.MemcacheDeleteResponse) MemcacheDeleteRequest(com.google.appengine.api.memcache.MemcacheServicePb.MemcacheDeleteRequest) ByteString(com.google.protobuf.ByteString) LatencyPercentiles(com.google.appengine.tools.development.LatencyPercentiles)

Example 2 with MemcacheDeleteResponse

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

the class MemcacheServiceImplTest method oneDeleteTest.

private void oneDeleteTest(MemcacheService memcache, String namespace, int timeoutMillis) {
    String[] keys = { ONE, null };
    for (String key : keys) {
        MemcacheDeleteRequest request = MemcacheDeleteRequest.newBuilder().setNameSpace(namespace).addItem(MemcacheDeleteRequest.Item.newBuilder().setKey(ByteString.copyFrom(makePbKey(key))).setDeleteTime(timeoutMillis / 1000)).build();
        MemcacheDeleteResponse response;
        if (timeoutMillis == 0) {
            response = MemcacheDeleteResponse.newBuilder().addDeleteStatus(MemcacheDeleteResponse.DeleteStatusCode.DELETED).build();
        } else {
            response = MemcacheDeleteResponse.newBuilder().addDeleteStatus(MemcacheDeleteResponse.DeleteStatusCode.NOT_FOUND).build();
        }
        expectAsyncCall("Delete", request, response);
        if (timeoutMillis == 0) {
            assertThat(memcache.delete(key)).isTrue();
        } else {
            assertThat(memcache.delete(key, timeoutMillis)).isFalse();
        }
        verifyAsyncCall("Delete", request);
    }
}
Also used : MemcacheDeleteResponse(com.google.appengine.api.memcache.MemcacheServicePb.MemcacheDeleteResponse) MemcacheDeleteRequest(com.google.appengine.api.memcache.MemcacheServicePb.MemcacheDeleteRequest) ByteString(com.google.protobuf.ByteString)

Example 3 with MemcacheDeleteResponse

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

the class MemcacheServiceImplTest method multiDeleteTest.

private void multiDeleteTest(MemcacheService memcache, String namespace, int timeoutMillis) {
    MemcacheDeleteRequest request = MemcacheDeleteRequest.newBuilder().setNameSpace(namespace).addItem(MemcacheDeleteRequest.Item.newBuilder().setKey(ByteString.copyFrom(makePbKey(ONE))).setDeleteTime(timeoutMillis / 1000)).addItem(MemcacheDeleteRequest.Item.newBuilder().setKey(ByteString.copyFrom(makePbKey(null))).setDeleteTime(timeoutMillis / 1000)).build();
    MemcacheDeleteResponse response;
    if (timeoutMillis == 0) {
        response = MemcacheDeleteResponse.newBuilder().addDeleteStatus(MemcacheDeleteResponse.DeleteStatusCode.NOT_FOUND).addDeleteStatus(MemcacheDeleteResponse.DeleteStatusCode.DELETED).build();
    } else {
        response = MemcacheDeleteResponse.newBuilder().addDeleteStatus(MemcacheDeleteResponse.DeleteStatusCode.DELETED).addDeleteStatus(MemcacheDeleteResponse.DeleteStatusCode.NOT_FOUND).build();
    }
    expectAsyncCall("Delete", request, response);
    ArrayList<String> collection = new ArrayList<>();
    collection.add(ONE);
    collection.add(null);
    if (timeoutMillis == 0) {
        Set<String> resp = memcache.deleteAll(collection);
        assertThat(resp).hasSize(1);
        assertThat(resp).contains(null);
    } else {
        Set<String> resp = memcache.deleteAll(collection, timeoutMillis);
        assertThat(resp).hasSize(1);
        assertThat(resp).contains(ONE);
    }
    verifyAsyncCall("Delete", request);
}
Also used : MemcacheDeleteResponse(com.google.appengine.api.memcache.MemcacheServicePb.MemcacheDeleteResponse) MemcacheDeleteRequest(com.google.appengine.api.memcache.MemcacheServicePb.MemcacheDeleteRequest) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString)

Aggregations

MemcacheDeleteRequest (com.google.appengine.api.memcache.MemcacheServicePb.MemcacheDeleteRequest)3 MemcacheDeleteResponse (com.google.appengine.api.memcache.MemcacheServicePb.MemcacheDeleteResponse)3 ByteString (com.google.protobuf.ByteString)3 LatencyPercentiles (com.google.appengine.tools.development.LatencyPercentiles)1 ArrayList (java.util.ArrayList)1