From 03216aa2585fdac7079a799af20d705c26f3e168 Mon Sep 17 00:00:00 2001 From: Donnerbart Date: Mon, 13 Feb 2017 12:36:26 +0100 Subject: [PATCH] Renamed MapTimeToLiveTest to MapTTLTest in HZ 3.6 test module --- .../simulator/tests/map/MapTTLTest.java | 141 ++++++++++++++++ .../tests/map/MapTimeToLiveTest.java | 155 ------------------ 2 files changed, 141 insertions(+), 155 deletions(-) create mode 100644 tests/tests-hz36/src/main/java/com/hazelcast/simulator/tests/map/MapTTLTest.java delete mode 100644 tests/tests-hz36/src/main/java/com/hazelcast/simulator/tests/map/MapTimeToLiveTest.java diff --git a/tests/tests-hz36/src/main/java/com/hazelcast/simulator/tests/map/MapTTLTest.java b/tests/tests-hz36/src/main/java/com/hazelcast/simulator/tests/map/MapTTLTest.java new file mode 100644 index 0000000000..9ad1facbc2 --- /dev/null +++ b/tests/tests-hz36/src/main/java/com/hazelcast/simulator/tests/map/MapTTLTest.java @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.hazelcast.simulator.tests.map; + +import com.hazelcast.core.IList; +import com.hazelcast.core.IMap; +import com.hazelcast.simulator.test.AbstractTest; +import com.hazelcast.simulator.test.BaseThreadState; +import com.hazelcast.simulator.test.annotations.AfterRun; +import com.hazelcast.simulator.test.annotations.Setup; +import com.hazelcast.simulator.test.annotations.TimeStep; +import com.hazelcast.simulator.test.annotations.Verify; +import com.hazelcast.simulator.tests.map.helpers.MapOperationCounter; +import com.hazelcast.simulator.utils.AssertTask; +import com.hazelcast.spi.exception.DistributedObjectDestroyedException; +import com.hazelcast.util.EmptyStatement; + +import java.util.concurrent.TimeUnit; + +import static com.hazelcast.simulator.utils.TestUtils.assertTrueEventually; +import static org.junit.Assert.assertEquals; + +/** + * In this test we are using map put methods with an expire time. + * + * We put keys at random into the map using sync and async methods with some probability distribution. + * In the end we verify that the map is empty and all key value pairs have expired out of the map. + */ +public class MapTTLTest extends AbstractTest { + + // properties + public int keyCount = 10; + public int maxTTLExpiryMs = 3000; + public int minTTLExpiryMs = 1; + + private IMap map; + private IList results; + + @Setup + public void setup() { + map = targetInstance.getMap(name); + results = targetInstance.getList(name + "report"); + } + + @TimeStep(prob = 0.4) + public void putTTL(ThreadState state) { + try { + int key = state.randomInt(keyCount); + int value = state.randomInt(); + int delayMs = minTTLExpiryMs + state.randomInt(maxTTLExpiryMs); + map.put(key, value, delayMs, TimeUnit.MILLISECONDS); + state.count.putTTLCount.incrementAndGet(); + } catch (DistributedObjectDestroyedException e) { + EmptyStatement.ignore(e); + } + } + + @TimeStep(prob = 0.3) + public void putAsyncTTL(ThreadState state) { + try { + int key = state.randomInt(keyCount); + int value = state.randomInt(); + int delayMs = minTTLExpiryMs + state.randomInt(maxTTLExpiryMs); + map.putAsync(key, value, delayMs, TimeUnit.MILLISECONDS); + state.count.putAsyncTTLCount.incrementAndGet(); + } catch (DistributedObjectDestroyedException e) { + EmptyStatement.ignore(e); + } + } + + @TimeStep(prob = 0.2) + public void get(ThreadState state) { + try { + int key = state.randomInt(keyCount); + map.get(key); + state.count.getCount.incrementAndGet(); + } catch (DistributedObjectDestroyedException e) { + EmptyStatement.ignore(e); + } + } + + @TimeStep(prob = 0.1) + public void getAsync(ThreadState state) { + try { + int key = state.randomInt(keyCount); + map.getAsync(key); + state.count.getAsyncCount.incrementAndGet(); + } catch (DistributedObjectDestroyedException e) { + EmptyStatement.ignore(e); + } + } + + @TimeStep(prob = 0) + public void destroy(ThreadState state) { + try { + map.destroy(); + state.count.destroyCount.incrementAndGet(); + } catch (DistributedObjectDestroyedException e) { + EmptyStatement.ignore(e); + } + } + + public class ThreadState extends BaseThreadState { + + private final MapOperationCounter count = new MapOperationCounter(); + } + + @AfterRun + public void afterRun(ThreadState state) { + results.add(state.count); + } + + @Verify + public void globalVerify() { + MapOperationCounter total = new MapOperationCounter(); + for (MapOperationCounter counter : results) { + total.add(counter); + } + logger.info(name + ": " + total + " total of " + results.size()); + + assertTrueEventually(new AssertTask() { + @Override + public void run() throws Exception { + assertEquals(name + ": Map should be empty, some TTL events are not processed", 0, map.size()); + } + }); + } +} diff --git a/tests/tests-hz36/src/main/java/com/hazelcast/simulator/tests/map/MapTimeToLiveTest.java b/tests/tests-hz36/src/main/java/com/hazelcast/simulator/tests/map/MapTimeToLiveTest.java deleted file mode 100644 index a3fd8db227..0000000000 --- a/tests/tests-hz36/src/main/java/com/hazelcast/simulator/tests/map/MapTimeToLiveTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.hazelcast.simulator.tests.map; - -import com.hazelcast.core.IList; -import com.hazelcast.core.IMap; -import com.hazelcast.simulator.test.AbstractTest; -import com.hazelcast.simulator.test.annotations.RunWithWorker; -import com.hazelcast.simulator.test.annotations.Setup; -import com.hazelcast.simulator.test.annotations.Verify; -import com.hazelcast.simulator.tests.map.helpers.MapOperationCounter; -import com.hazelcast.simulator.utils.AssertTask; -import com.hazelcast.simulator.worker.selector.OperationSelectorBuilder; -import com.hazelcast.simulator.worker.tasks.AbstractWorker; -import com.hazelcast.spi.exception.DistributedObjectDestroyedException; -import com.hazelcast.util.EmptyStatement; - -import java.util.concurrent.TimeUnit; - -import static com.hazelcast.simulator.utils.TestUtils.assertTrueEventually; -import static org.junit.Assert.assertEquals; - -/** - * In this test we are using map put methods with an expire time. - * - * We put keys at random into the map using sync and async methods with some probability distribution. - * In the end we verify that the map is empty and all key value pairs have expired out of the map. - */ -public class MapTimeToLiveTest extends AbstractTest { - - private enum Operation { - PUT_TTL, - ASYNC_PUT_TTL, - GET, - ASYNC_GET, - DESTROY - } - - // properties - public int keyCount = 10; - - public double putTTLProb = 0.4; - public double putAsyncTTLProb = 0.3; - public double getProb = 0.2; - public double getAsyncProb = 0.1; - public double destroyProb = 0.0; - - public int maxTTLExpiryMs = 3000; - public int minTTLExpiryMs = 1; - - private final OperationSelectorBuilder builder = new OperationSelectorBuilder(); - - private IMap map; - private IList results; - - @Setup - public void setup() { - map = targetInstance.getMap(name); - results = targetInstance.getList(name + "report"); - - builder.addOperation(Operation.PUT_TTL, putTTLProb) - .addOperation(Operation.ASYNC_PUT_TTL, putAsyncTTLProb) - .addOperation(Operation.GET, getProb) - .addOperation(Operation.ASYNC_GET, getAsyncProb) - .addOperation(Operation.DESTROY, destroyProb); - } - - @RunWithWorker - public Worker createWorker() { - return new Worker(); - } - - private class Worker extends AbstractWorker { - - private final MapOperationCounter count = new MapOperationCounter(); - - public Worker() { - super(builder); - } - - @Override - protected void timeStep(Operation operation) throws Exception { - try { - int key = randomInt(keyCount); - int value; - int delayMs; - - switch (operation) { - case PUT_TTL: - value = randomInt(); - delayMs = minTTLExpiryMs + randomInt(maxTTLExpiryMs); - map.put(key, value, delayMs, TimeUnit.MILLISECONDS); - count.putTTLCount.incrementAndGet(); - break; - case ASYNC_PUT_TTL: - value = randomInt(); - delayMs = minTTLExpiryMs + randomInt(maxTTLExpiryMs); - map.putAsync(key, value, delayMs, TimeUnit.MILLISECONDS); - count.putAsyncTTLCount.incrementAndGet(); - break; - case GET: - map.get(key); - count.getCount.incrementAndGet(); - break; - case ASYNC_GET: - map.getAsync(key); - count.getAsyncCount.incrementAndGet(); - break; - case DESTROY: - map.destroy(); - count.destroyCount.incrementAndGet(); - break; - default: - throw new UnsupportedOperationException(); - } - } catch (DistributedObjectDestroyedException e) { - EmptyStatement.ignore(e); - } - } - - @Override - public void afterRun() { - results.add(count); - } - } - - @Verify - public void globalVerify() { - MapOperationCounter total = new MapOperationCounter(); - for (MapOperationCounter counter : results) { - total.add(counter); - } - logger.info(name + ": " + total + " total of " + results.size()); - - assertTrueEventually(new AssertTask() { - @Override - public void run() throws Exception { - assertEquals(name + ": Map should be empty, some TTL events are not processed", 0, map.size()); - } - }); - } -}