//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void randomizedTest() internal virtual void RandomizedTest() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int count = 10000 + rnd.nextInt(1000); int count = 10000 + _rnd.Next(1000); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.eclipse.collections.api.map.primitive.MutableLongLongMap m = new org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap(); MutableLongLongMap m = new LongLongHashMap(); while (m.size() < count) { m.put(_rnd.nextLong(), _rnd.nextLong()); } m.forEachKeyValue((k, v) => { assertFalse(_map.containsKey(k)); _map.put(k, v); assertTrue(_map.containsKey(k)); assertEquals(v, _map.get(k)); assertEquals(v, _map.getOrThrow(k)); assertEquals(v, _map.getIfAbsent(k, v * 2)); assertEquals(v, _map.getIfAbsentPut(k, v * 2)); assertEquals(v, _map.getIfAbsentPut(k, () => v * 2)); }); assertEquals(m.size(), _map.size()); assertTrue(m.Keys.allSatisfy(_map.containsKey)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<org.eclipse.collections.api.tuple.primitive.LongLongPair> toRemove = m.keyValuesView().select(p -> rnd.nextInt(100) < 75).toList().shuffleThis(rnd.random()); IList <LongLongPair> toRemove = m.keyValuesView().select(p => _rnd.Next(100) < 75).toList().shuffleThis(_rnd.random()); toRemove.ForEach(p => { long k = p.One; long v = p.Two; _map.updateValue(k, v + 1, x => - x); assertEquals(-v, _map.get(k)); _map.remove(k); assertEquals(v * 2, _map.removeKeyIfAbsent(k, v * 2)); assertEquals(v * 2, _map.getIfAbsent(k, v * 2)); assertFalse(_map.containsKey(k)); assertThrows(typeof(System.InvalidOperationException), () => _map.getOrThrow(k)); _map.updateValue(k, v + 42, x => - x); assertEquals(-v - 42, _map.get(k)); }); toRemove.ForEach(p => _map.removeKey(p.One)); assertEquals(count - toRemove.Count, _map.size()); }
private void Remove(int count, ValuesMap actualMap, MutableLongObjectMap <Value> expectedMap) { for (int i = 0; i < count / 2; i++) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long key = rnd.nextLong(count); long key = _rnd.nextLong(count); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.values.storable.Value value = rnd.randomValues().nextValue(); Value value = _rnd.randomValues().nextValue(); actualMap.Put(key, value); expectedMap.put(key, value); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldReadWriteSingleEntry() internal virtual void ShouldReadWriteSingleEntry() { // given MutableLong writeKey = _layout.key(Rnd.nextLong()); MutableLong writeValue = _layout.value(Rnd.nextLong()); int offset = _pageCursor.Offset; BlockEntry.Write(_pageCursor, _layout, writeKey, writeValue); // when MutableLong readKey = _layout.newKey(); MutableLong readValue = _layout.newValue(); _pageCursor.Offset = offset; BlockEntry.Read(_pageCursor, _layout, readKey, readValue); // then assertEquals(0, _layout.Compare(writeKey, readKey)); assertEquals(0, _layout.Compare(writeValue, readValue)); }
private void UpdateOldNodes(LongStream idRange) { using (Transaction transaction = Database.beginTx()) { IList <Node> nodes = idRange.mapToObj(id => Database.getNodeById(id)).collect(Collectors.toList()); for (int i = 0; i < NUMBER_OF_INDEXES; i++) { string propertyName = PROPERTY_PREFIX + i; nodes.ForEach(node => node.setProperty(propertyName, RandomRule.nextLong())); } transaction.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPutRandomStuff() public virtual void ShouldPutRandomStuff() { // GIVEN int typeId = 10; int nodes = 10_000; MutableLongObjectMap <long[]> key = new LongObjectHashMap <long[]>(nodes); _cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 1, 1000, Base); // mark random nodes as dense (dense node threshold is 1 so enough with one increment _cache.NodeCount = nodes; for (long nodeId = 0; nodeId < nodes; nodeId++) { if (Random.nextBoolean()) { _cache.incrementCount(nodeId); } } // WHEN for (int i = 0; i < 100_000; i++) { long nodeId = Random.nextLong(nodes); bool dense = _cache.isDense(nodeId); Direction direction = Random.among(Direction.values()); long relationshipId = Random.nextLong(1_000_000); long previousHead = _cache.getAndPutRelationship(nodeId, typeId, direction, relationshipId, false); long[] keyIds = key.get(nodeId); int keyIndex = dense ? direction.ordinal() : 0; if (keyIds == null) { key.put(nodeId, keyIds = MinusOneLongs(Direction.values().length)); } assertEquals(keyIds[keyIndex], previousHead); keyIds[keyIndex] = relationshipId; } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldStoreAndLoadLongs() public virtual void ShouldStoreAndLoadLongs() { // given using (LongCollisionValues values = new LongCollisionValues(Factory, 100)) { // when long[] offsets = new long[100]; long[] longs = new long[offsets.Length]; for (int i = 0; i < offsets.Length; i++) { long value = Random.nextLong(long.MaxValue); offsets[i] = values.Add(value); longs[i] = value; } // then for (int i = 0; i < offsets.Length; i++) { assertEquals(longs[i], ( long )values.Get(offsets[i])); } } }
public static ICollection <NumberArrayTestData> Arrays() { PageCache pageCache = _fixture.pageCache; File dir = _fixture.directory; ICollection <NumberArrayTestData> list = new List <NumberArrayTestData>(); IDictionary <string, NumberArrayFactory> factories = new Dictionary <string, NumberArrayFactory>(); factories["HEAP"] = HEAP; factories["OFF_HEAP"] = OFF_HEAP; factories["AUTO_WITHOUT_PAGECACHE"] = AUTO_WITHOUT_PAGECACHE; factories["CHUNKED_FIXED_SIZE"] = CHUNKED_FIXED_SIZE; factories["autoWithPageCacheFallback"] = auto(pageCache, dir, true, NO_MONITOR); factories["PageCachedNumberArrayFactory"] = new PageCachedNumberArrayFactory(pageCache, dir); foreach (KeyValuePair <string, NumberArrayFactory> entry in factories.SetOfKeyValuePairs()) { string name = entry.Key + " => "; NumberArrayFactory factory = entry.Value; //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: list.Add(ArrayData(name + "IntArray", factory.NewIntArray(INDEXES, -1), _random => _random.Next(1_000_000_000), (array, index, value) => array.set(index, ( int? )value), IntArray::get)); //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: list.Add(ArrayData(name + "DynamicIntArray", factory.NewDynamicIntArray(_chunkSize, -1), _random => _random.Next(1_000_000_000), (array, index, value) => array.set(index, ( int? )value), IntArray::get)); //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: list.Add(ArrayData(name + "LongArray", factory.NewLongArray(INDEXES, -1), _random => _random.nextLong(1_000_000_000), (array, index, value) => array.set(index, ( long? )value), LongArray::get)); //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: list.Add(ArrayData(name + "DynamicLongArray", factory.NewDynamicLongArray(_chunkSize, -1), _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)), _random => _random.Next(1_000_000_000), (array, index, value) => array.setInt(index, 1, ( int? )value), (array, index) => array.getInt(index, 1))); list.Add(ArrayData(name + "DynamicByteArray5", factory.NewDynamicByteArray(_chunkSize, DefaultByteArray(5)), _random => _random.Next(1_000_000_000), (array, index, value) => array.setInt(index, 1, ( int? )value), (array, index) => array.getInt(index, 1))); System.Func <RandomRule, object> valueGenerator = _random => new long[] { _random.nextLong(), _random.Next(), (short)_random.Next(), (sbyte)_random.Next() }; 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, ( sbyte )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)), valueGenerator, writer, reader)); list.Add(ArrayData(name + "DynamicByteArray15", factory.NewDynamicByteArray(_chunkSize, DefaultByteArray(15)), valueGenerator, writer, reader)); } return(list); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldInsertAndRemoveRandomKeysAndValues() internal virtual void ShouldInsertAndRemoveRandomKeysAndValues() { // This test doesn't care about sorting, that's an aspect that lies outside of TreeNode, really // GIVEN _node.initializeLeaf(Cursor, STABLE_GENERATION, UNSTABLE_GENERATION); // add +1 to these to simplify some array logic in the test itself IList <KEY> expectedKeys = new List <KEY>(); IList <VALUE> expectedValues = new List <VALUE>(); int expectedKeyCount = 0; KEY readKey = _layout.newKey(); VALUE readValue = _layout.newValue(); // WHEN/THEN for (int i = 0; i < 1000; i++) { if (_random.nextFloat() < 0.7) { // 70% insert KEY newKey; do { newKey = Key(_random.nextLong()); } while (contains(expectedKeys, newKey, _layout)); VALUE newValue = Value(_random.nextLong()); Overflow overflow = _node.leafOverflow(Cursor, expectedKeyCount, newKey, newValue); if (overflow == NO_NEED_DEFRAG) { _node.defragmentLeaf(Cursor); } if (overflow != YES) { // there's room int position = expectedKeyCount == 0 ? 0 : _random.Next(expectedKeyCount); // ensure unique _node.insertKeyValueAt(Cursor, newKey, newValue, position, expectedKeyCount); expectedKeys.Insert(position, newKey); expectedValues.Insert(position, newValue); TreeNode.SetKeyCount(Cursor, ++expectedKeyCount); } } else { // 30% remove if (expectedKeyCount > 0) { // there are things to remove int position = _random.Next(expectedKeyCount); _node.keyAt(Cursor, readKey, position, LEAF); _node.valueAt(Cursor, readValue, position); _node.removeKeyValueAt(Cursor, position, expectedKeyCount); KEY expectedKey = expectedKeys.RemoveAt(position); VALUE expectedValue = expectedValues.RemoveAt(position); //JAVA TO C# CONVERTER TODO TASK: The following line has a Java format specifier which cannot be directly translated to .NET: //ORIGINAL LINE: assertEquals(0, layout.compare(expectedKey, readKey), String.format("Key differ with expected%n readKey=%s %nexpectedKey=%s%n", readKey, expectedKey)); assertEquals(0, _layout.Compare(expectedKey, readKey), string.Format("Key differ with expected%n readKey=%s %nexpectedKey=%s%n", readKey, expectedKey)); assertEquals(0, _layout.compareValue(expectedValue, readValue), "Value differ with expected, value=" + readValue + ", expectedValue=" + expectedValue); TreeNode.SetKeyCount(Cursor, --expectedKeyCount); } } } // THEN AssertContent(expectedKeys, expectedValues, expectedKeyCount); }