use of org.neo4j.test.rule.RandomRule in project neo4j by neo4j.
the class GBPTreeGenericCountsStoreTest method generateAndApplyTransaction.
/**
* Generates a transaction, i.e. a counts change set. The data is random, but uses a seed which is the seed of the {@link RandomRule} in this test
* as well as the the supplied txId. Calling this method in any given test multiple times with any specific txId will generate the same data.
*
* @param expected map of counts to update with the generated changes.
* @param txId transaction id to generate transaction data for and ultimately apply to the counts store (and the expected map).
*/
private void generateAndApplyTransaction(ConcurrentMap<CountsKey, AtomicLong> expected, long txId) {
Random rng = new Random(random.seed() + txId);
try (CountUpdater updater = countsStore.updater(txId, NULL)) {
if (updater != null) {
int numberOfKeys = rng.nextInt(10);
for (int j = 0; j < numberOfKeys; j++) {
// chance to get -1
long delta = rng.nextInt(11) - 1;
CountsKey expectedKey;
if (rng.nextBoolean()) {
// Node
int labelId = randomTokenId(rng);
updater.increment(nodeKey(labelId), delta);
expectedKey = nodeKey(labelId);
} else {
// Relationship
int startLabelId = randomTokenId(rng);
int type = randomTokenId(rng);
int endLabelId = randomTokenId(rng);
updater.increment(relationshipKey(startLabelId, type, endLabelId), delta);
expectedKey = relationshipKey(startLabelId, type, endLabelId);
}
expected.computeIfAbsent(expectedKey, k -> new AtomicLong()).addAndGet(delta);
}
}
}
}
use of org.neo4j.test.rule.RandomRule in project neo4j by neo4j.
the class RandomExtension method createField.
@Override
protected RandomRule createField(ExtensionContext extensionContext) {
RandomRule randomRule = new RandomRule();
randomRule.setSeed(System.currentTimeMillis());
return randomRule;
}
use of org.neo4j.test.rule.RandomRule in project neo4j by neo4j.
the class NumberArrayTest method arrays.
public static Collection<NumberArrayTestData> arrays() {
PageCache pageCache = fixture.pageCache;
Path dir = fixture.directory;
NullLog log = NullLog.getInstance();
Collection<NumberArrayTestData> list = new ArrayList<>();
Map<String, NumberArrayFactory> factories = new HashMap<>();
factories.put("HEAP", NumberArrayFactories.HEAP);
factories.put("OFF_HEAP", NumberArrayFactories.OFF_HEAP);
factories.put("AUTO_WITHOUT_PAGECACHE", NumberArrayFactories.AUTO_WITHOUT_PAGECACHE);
factories.put("CHUNKED_FIXED_SIZE", NumberArrayFactories.CHUNKED_FIXED_SIZE);
factories.put("autoWithPageCacheFallback", NumberArrayFactories.auto(pageCache, NULL, dir, true, NO_MONITOR, log, DEFAULT_DATABASE_NAME));
factories.put("PageCachedNumberArrayFactory", new PageCachedNumberArrayFactory(pageCache, NULL, dir, log, DEFAULT_DATABASE_NAME));
for (Map.Entry<String, NumberArrayFactory> entry : factories.entrySet()) {
String name = entry.getKey() + " => ";
NumberArrayFactory factory = entry.getValue();
list.add(arrayData(name + "IntArray", factory.newIntArray(INDEXES, -1, INSTANCE), random -> random.nextInt(1_000_000_000), (array, index, value) -> array.set(index, (Integer) value), IntArray::get));
list.add(arrayData(name + "DynamicIntArray", factory.newDynamicIntArray(CHUNK_SIZE, -1, INSTANCE), random -> random.nextInt(1_000_000_000), (array, index, value) -> array.set(index, (Integer) value), IntArray::get));
list.add(arrayData(name + "LongArray", factory.newLongArray(INDEXES, -1, INSTANCE), random -> random.nextLong(1_000_000_000), (array, index, value) -> array.set(index, (Long) value), LongArray::get));
list.add(arrayData(name + "DynamicLongArray", factory.newDynamicLongArray(CHUNK_SIZE, -1, INSTANCE), random -> random.nextLong(1_000_000_000), (array, index, value) -> array.set(index, (Long) value), LongArray::get));
list.add(arrayData(name + "ByteArray5", factory.newByteArray(INDEXES, defaultByteArray(5), INSTANCE), random -> random.nextInt(1_000_000_000), (array, index, value) -> array.setInt(index, 1, (Integer) value), (array, index) -> array.getInt(index, 1)));
list.add(arrayData(name + "DynamicByteArray5", factory.newDynamicByteArray(CHUNK_SIZE, defaultByteArray(5), INSTANCE), random -> random.nextInt(1_000_000_000), (array, index, value) -> array.setInt(index, 1, (Integer) value), (array, index) -> array.getInt(index, 1)));
Function<RandomRule, Object> valueGenerator = random -> new long[] { random.nextLong(), random.nextInt(), (short) random.nextInt(), (byte) random.nextInt() };
Writer<ByteArray> writer = (array, index, value) -> {
long[] values = (long[]) value;
array.setLong(index, 0, values[0]);
array.setInt(index, 8, (int) values[1]);
array.setShort(index, 12, (short) values[2]);
array.setByte(index, 14, (byte) values[3]);
};
Reader<ByteArray> reader = (array, index) -> new long[] { array.getLong(index, 0), array.getInt(index, 8), array.getShort(index, 12), array.getByte(index, 14) };
list.add(arrayData(name + "ByteArray15", factory.newByteArray(INDEXES, defaultByteArray(15), INSTANCE), valueGenerator, writer, reader));
list.add(arrayData(name + "DynamicByteArray15", factory.newDynamicByteArray(CHUNK_SIZE, defaultByteArray(15), INSTANCE), valueGenerator, writer, reader));
}
return list;
}
Aggregations