com.hazelcast.simulator.tests.map.MultiValueMapTest 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.IMap;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.DataSerializable;
import com.hazelcast.nio.serialization.Portable;
import com.hazelcast.nio.serialization.PortableFactory;
import com.hazelcast.nio.serialization.PortableReader;
import com.hazelcast.nio.serialization.PortableWriter;
import com.hazelcast.query.Predicate;
import com.hazelcast.query.Predicates;
import com.hazelcast.simulator.probes.Probe;
import com.hazelcast.simulator.test.annotations.RunWithWorker;
import com.hazelcast.simulator.test.annotations.Setup;
import com.hazelcast.simulator.test.annotations.Warmup;
import com.hazelcast.simulator.test.AbstractTest;
import com.hazelcast.simulator.utils.ThrottlingLogger;
import com.hazelcast.simulator.worker.loadsupport.Streamer;
import com.hazelcast.simulator.worker.loadsupport.StreamerFactory;
import com.hazelcast.simulator.worker.selector.OperationSelectorBuilder;
import com.hazelcast.simulator.worker.tasks.AbstractWorkerWithMultipleProbes;
import org.apache.commons.lang3.ArrayUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import static java.lang.Math.abs;
import static java.lang.String.format;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
public class MultiValueMapTest extends AbstractTest {
private enum Operation {
PUT,
QUERY,
}
public int keyCount = 100000;
public int maxNestedValues = 100;
public double putProbability = 0.5;
public boolean useIndex;
public boolean usePortable;
private final ThrottlingLogger throttlingLogger = ThrottlingLogger.newLogger(logger, 5000);
private final OperationSelectorBuilder operationSelectorBuilder = new OperationSelectorBuilder();
private IMap map;
@Setup
public void setUp() {
map = targetInstance.getMap(name);
operationSelectorBuilder
.addOperation(Operation.PUT, putProbability)
.addDefaultOperation(Operation.QUERY);
}
@Warmup(global = true)
public void warmup() {
if (useIndex) {
map.addIndex("payloadField[any]", true);
}
loadInitialData();
}
private void loadInitialData() {
Streamer streamer = StreamerFactory.getInstance(map);
for (int i = 0; i < keyCount; i++) {
int count = i % maxNestedValues;
SillySequence sillySequence = new SillySequence(i, count);
streamer.pushEntry(i, sillySequence);
}
streamer.await();
}
@RunWithWorker
public Worker createWorker() {
return new Worker(operationSelectorBuilder);
}
private class Worker extends AbstractWorkerWithMultipleProbes {
public Worker(OperationSelectorBuilder operationSelectorBuilder) {
super(operationSelectorBuilder);
}
private int getRandomKey() {
return abs(randomInt(keyCount));
}
@Override
protected void timeStep(Operation operation, Probe probe) throws Exception {
int key = getRandomKey();
long started;
switch (operation) {
case PUT:
int count = key % maxNestedValues;
SillySequence sillySequence = new SillySequence(key, count);
started = System.nanoTime();
map.put(key, usePortable ? sillySequence.getPortable() : sillySequence);
probe.done(started);
break;
case QUERY:
Predicate predicate = Predicates.equal("payloadField[any]", key);
started = System.nanoTime();
Collection © 2015 - 2025 Weber Informatics LLC | Privacy Policy