Skip to content

Commit

Permalink
Add Map.delete to remove statistic on client
Browse files Browse the repository at this point in the history
  • Loading branch information
sancar committed Feb 21, 2019
1 parent b04e92c commit e6009b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Expand Up @@ -19,6 +19,7 @@
import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.client.impl.protocol.codec.MapDeleteCodec;
import com.hazelcast.instance.Node;
import com.hazelcast.map.impl.MapContainer;
import com.hazelcast.map.impl.MapService;
import com.hazelcast.map.impl.operation.MapOperation;
import com.hazelcast.map.impl.operation.MapOperationProvider;
Expand All @@ -32,6 +33,8 @@
public class MapDeleteMessageTask
extends AbstractMapPartitionMessageTask<MapDeleteCodec.RequestParameters> {

private transient long startTimeNanos;

public MapDeleteMessageTask(ClientMessage clientMessage, Node node, Connection connection) {
super(clientMessage, node, connection);
}
Expand All @@ -44,6 +47,22 @@ protected Operation prepareOperation() {
return op;
}

@Override
protected void beforeProcess() {
startTimeNanos = System.nanoTime();
}

@Override
protected void beforeResponse() {
final long latencyNanos = System.nanoTime() - startTimeNanos;
final MapService mapService = getService(MapService.SERVICE_NAME);
MapContainer mapContainer = mapService.getMapServiceContext().getMapContainer(parameters.name);
if (mapContainer.getMapConfig().isStatisticsEnabled()) {
mapService.getMapServiceContext().getLocalMapStatsProvider().getLocalMapStatsImpl(parameters.name)
.incrementRemoveLatencyNanos(latencyNanos);
}
}

@Override
protected MapDeleteCodec.RequestParameters decodeClientMessage(ClientMessage clientMessage) {
return MapDeleteCodec.decodeRequest(clientMessage);
Expand Down
11 changes: 11 additions & 0 deletions hazelcast/src/test/java/com/hazelcast/map/LocalMapStatsTest.java
Expand Up @@ -162,6 +162,17 @@ public void run()
});
}

@Test
public void testDelete() throws Exception {
IMap<Integer, Integer> map = getMap();
for (int i = 0; i < 100; i++) {
map.put(i, i);
map.delete(i);
}
LocalMapStats localMapStats = geMapStats();
assertEquals(100, localMapStats.getRemoveOperationCount());
}

@Test
public void testRemove() throws Exception {
IMap<Integer, Integer> map = getMap();
Expand Down

0 comments on commit e6009b0

Please sign in to comment.