com.hazelcast.simulator.tests.map.ExtractorMapTest Maven / Gradle / Ivy
The newest version!
/*
* 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.config.IndexType;
import com.hazelcast.map.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.query.extractor.ValueCollector;
import com.hazelcast.query.extractor.ValueExtractor;
import com.hazelcast.query.extractor.ValueReader;
import com.hazelcast.simulator.hz.HazelcastTest;
import com.hazelcast.simulator.probes.Probe;
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.StartNanos;
import com.hazelcast.simulator.test.annotations.TimeStep;
import com.hazelcast.simulator.utils.ThrottlingLogger;
import com.hazelcast.simulator.worker.loadsupport.Streamer;
import com.hazelcast.simulator.worker.loadsupport.StreamerFactory;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.log4j.Level;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static java.lang.Math.abs;
import static java.lang.String.format;
import static org.junit.Assert.assertEquals;
public class ExtractorMapTest extends HazelcastTest {
public int keyCount = 100000;
public int nestedValuesCount = 100;
public int indexValuesCount = 5;
public boolean useIndex;
public boolean usePortable;
private final ThrottlingLogger throttlingLogger = ThrottlingLogger.newLogger(logger, 5000);
private IMap map;
@Setup
public void setUp() {
String mapName = usePortable ? "Portable " + name : name;
map = targetInstance.getMap(mapName);
}
@Prepare(global = true)
public void globalPrepare() {
if (useIndex) {
for (int i = 0; i < indexValuesCount; i++) {
map.addIndex(IndexType.SORTED, format("payloadFromExtractor[%d]", i));
}
}
loadInitialData();
}
private void loadInitialData() {
Streamer streamer = StreamerFactory.getInstance(map);
for (int i = 0; i < keyCount; i++) {
SillySequence sillySequence = new SillySequence(i, nestedValuesCount);
streamer.pushEntry(i, usePortable ? sillySequence.getPortable() : sillySequence);
}
streamer.await();
}
@TimeStep(prob = 0.5)
public void put(ThreadState state) {
int key = state.getRandomKey();
SillySequence sillySequence = new SillySequence(key, nestedValuesCount);
map.put(key, usePortable ? sillySequence.getPortable() : sillySequence);
}
@TimeStep(prob = -1)
public void query(ThreadState state, Probe probe, @StartNanos long startedNanos) {
int key = state.getRandomKey();
int index = key % nestedValuesCount;
String query = format("payloadFromExtractor[%d]", index);
Predicate predicate = Predicates.equal(query, key);
Collection © 2015 - 2025 Weber Informatics LLC | Privacy Policy