com.hazelcast.simulator.tests.map.BackupExpirationMapTest Maven / Gradle / Ivy
/*
* 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.HazelcastInstance;
import com.hazelcast.map.IMap;
import com.hazelcast.map.LocalMapStats;
import com.hazelcast.simulator.hz.HazelcastTest;
import com.hazelcast.simulator.test.BaseThreadState;
import com.hazelcast.simulator.test.annotations.Prepare;
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.helpers.KeyLocality;
import com.hazelcast.simulator.worker.loadsupport.Streamer;
import com.hazelcast.simulator.worker.loadsupport.StreamerFactory;
import java.util.Random;
import static com.hazelcast.simulator.tests.helpers.HazelcastTestUtils.waitClusterSize;
import static com.hazelcast.simulator.tests.helpers.KeyUtils.generateIntKeys;
import static com.hazelcast.simulator.utils.TestUtils.assertTrueEventually;
import static org.junit.Assert.assertEquals;
public class BackupExpirationMapTest extends HazelcastTest {
// properties
public int minNumberOfMembers = 0;
public int keyCount = 10000;
public KeyLocality keyLocality = KeyLocality.SHARED;
private IMap map;
private int[] keys;
@Setup
public void setUp() {
map = targetInstance.getMap(name);
}
@Prepare(global = false)
public void prepare() {
waitClusterSize(logger, targetInstance, minNumberOfMembers);
keys = generateIntKeys(keyCount, keyLocality, targetInstance);
Streamer streamer = StreamerFactory.getInstance(map);
Random random = new Random();
for (int key : keys) {
int value = random.nextInt(Integer.MAX_VALUE);
streamer.pushEntry(key, value);
}
streamer.await();
}
@TimeStep(prob = 0.1)
public Integer put(ThreadState state) {
int key = state.randomKey();
int value = state.randomValue();
return map.put(key, value);
}
@TimeStep(prob = -1)
public Integer get(ThreadState state) {
int key = state.randomKey();
return map.get(key);
}
@Verify(global = false)
public void verify() {
assertTrueEventually(() -> {
long totalEntryCount = totalEntryCountOnNode(name, targetInstance);
assertEquals("totalEntryCount=" + totalEntryCount, 0, totalEntryCount);
}, 600);
}
private static long totalEntryCountOnNode(String name, HazelcastInstance instance) {
IMap map = instance.getMap(name);
LocalMapStats localMapStats = map.getLocalMapStats();
long ownedEntryCount = localMapStats.getOwnedEntryCount();
long backupEntryCount = localMapStats.getBackupEntryCount();
return ownedEntryCount + backupEntryCount;
}
public class ThreadState extends BaseThreadState {
private int randomKey() {
return keys[randomInt(keys.length)];
}
private int randomValue() {
return randomInt(Integer.MAX_VALUE);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy