//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private <R extends org.neo4j.kernel.impl.store.record.AbstractBaseRecord> void verifyWriteAndRead(System.Func<RecordFormat<R>> formatSupplier, System.Func<org.neo4j.kernel.impl.store.format.RecordGenerators_Generator<R>> generatorSupplier, System.Func<RecordKey<R>> keySupplier, boolean assertPostReadOffset) throws java.io.IOException private void VerifyWriteAndRead <R>(System.Func <RecordFormat <R> > formatSupplier, System.Func <RecordGenerators_Generator <R> > generatorSupplier, System.Func <RecordKey <R> > keySupplier, bool assertPostReadOffset) where R : Org.Neo4j.Kernel.impl.store.record.AbstractBaseRecord { // GIVEN using (PagedFile storeFile = _pageCache.map(new File("store-" + Name.MethodName), _pageSize, CREATE)) { RecordFormat <R> format = formatSupplier(); RecordKey <R> key = keySupplier(); RecordGenerators_Generator <R> generator = generatorSupplier(); int recordSize = format.GetRecordSize(new IntStoreHeader(DATA_SIZE)); BatchingIdSequence idSequence = new BatchingIdSequence(_random.nextBoolean() ? IdSureToBeOnTheNextPage(_pageSize, recordSize) : 10); // WHEN long time = currentTimeMillis(); long endTime = time + TEST_TIME; long i = 0; for ( ; i < TEST_ITERATIONS && currentTimeMillis() < endTime; i++) { R written = generator.Get(recordSize, format, i % 5); R read = format.NewRecord(); try { WriteRecord(written, format, storeFile, recordSize, idSequence); ReadAndVerifyRecord(written, read, format, key, storeFile, recordSize, assertPostReadOffset); idSequence.Reset(); } catch (Exception t) { Exceptions.setMessage(t, t.Message + " : written:" + written + ", read:" + read + ", seed:" + _random.seed() + ", iteration:" + i); throw t; } } } }
//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 java.util.List<org.eclipse.collections.api.tuple.primitive.ObjectLongPair<org.neo4j.values.storable.Value>> valueRefPairs = new java.util.ArrayList<>(); IList <ObjectLongPair <Value> > valueRefPairs = new List <ObjectLongPair <Value> >(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.eclipse.collections.api.list.MutableList<org.eclipse.collections.api.tuple.primitive.ObjectLongPair<org.neo4j.values.storable.Value>> toRemove = new org.eclipse.collections.impl.list.mutable.FastList<>(); MutableList <ObjectLongPair <Value> > toRemove = new FastList <ObjectLongPair <Value> >(); for (int i = 0; i < count; i++) { //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(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long ref = container.add(value); long @ref = _container.add(value); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.eclipse.collections.api.tuple.primitive.ObjectLongPair<org.neo4j.values.storable.Value> pair = pair(value, ref); ObjectLongPair <Value> pair = pair(value, @ref); if (_rnd.nextBoolean()) { toRemove.add(pair); } else { valueRefPairs.Add(pair); } } toRemove.shuffleThis(_rnd.random()); foreach (ObjectLongPair <Value> valueRefPair in toRemove) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.values.storable.Value removed = container.remove(valueRefPair.getTwo()); Value removed = _container.remove(valueRefPair.Two); assertEquals(valueRefPair.One, removed); assertThrows(typeof(System.ArgumentException), () => _container.remove(valueRefPair.Two)); assertThrows(typeof(System.ArgumentException), () => _container.get(valueRefPair.Two)); } foreach (ObjectLongPair <Value> valueRefPair in valueRefPairs) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.values.storable.Value actualValue = container.get(valueRefPair.getTwo()); Value actualValue = _container.get(valueRefPair.Two); assertEquals(valueRefPair.One, actualValue); } }
private Label[] RandomLabels() { IList <Label> labels = new List <Label>(3); foreach (Label label in _labelAlphabet) { if (Random.nextBoolean()) { labels.Add(label); } } return(labels.ToArray()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldScanAllInUseRelationships() public virtual void ShouldScanAllInUseRelationships() { // given RelationshipStore relationshipStore = _neoStores.RelationshipStore; int count = 100; relationshipStore.HighId = count; ISet <long> expected = new HashSet <long>(); for (long id = 0; id < count; id++) { bool inUse = Random.nextBoolean(); CreateRelationshipRecord(id, 1, relationshipStore, inUse); if (inUse) { expected.Add(id); } } // when AssertSeesRelationships(expected, ANY_RELATIONSHIP_TYPE); }
//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; } }
private long[] RandomNodes(Ids[] ids) { long[] nodeIds = new long[ids.Length]; int cursor = 0; foreach (Ids id in ids) { if (random.nextBoolean()) { nodeIds[cursor++] = id.Node.Id; } } // If none was selected, then pick just one if (cursor == 0) { nodeIds[cursor++] = random.among(ids).node.Id; } return(Arrays.copyOf(nodeIds, cursor)); }
private void MarkRandomRelsInChainNotInUse(long relId) { if (relId != NO_NEXT_RELATIONSHIP.intValue()) { RelationshipRecord record = GetRelRecord(relId); bool shouldBeMarked = Random.nextBoolean(); if (shouldBeMarked) { record.InUse = false; Update(record); } MarkRandomRelsInChainNotInUse(record.FirstNextRel); bool isLoopRelationship = record.FirstNextRel == record.SecondNextRel; if (!isLoopRelationship) { MarkRandomRelsInChainNotInUse(record.SecondNextRel); } } }
/* * There was this issue that DynamicNodeLabels#add would consider even unused dynamic records when * reading existing label ids before making the change. Previously this would create a duplicate * last label id (the one formerly being in the second record). * * This randomized test found this issue every time when it existed and it will potentially find other * unforeseen issues as well. */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleRandomAddsAndRemoves() public virtual void ShouldHandleRandomAddsAndRemoves() { // GIVEN ISet <int> key = new HashSet <int>(); NodeRecord node = new NodeRecord(0); node.InUse = true; // WHEN for (int i = 0; i < 100_000; i++) { NodeLabels labels = NodeLabelsField.parseLabelsField(node); int labelId = Random.Next(200); if (Random.nextBoolean()) { if (!key.Contains(labelId)) { labels.Add(labelId, _nodeStore, _nodeStore.DynamicLabelStore); key.Add(labelId); } } else { if (key.remove(labelId)) { labels.Remove(labelId, _nodeStore); } } } // THEN NodeLabels labels = NodeLabelsField.parseLabelsField(node); long[] readLabelIds = labels.Get(_nodeStore); foreach (long labelId in readLabelIds) { assertTrue("Found an unexpected label " + labelId, key.remove(( int )labelId)); } assertTrue(key.Count == 0); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldHandleStringPredicates() internal virtual void ShouldHandleStringPredicates() { for (int i = 0; i < ITERATIONS; i++) { string value = _random.nextString(); string other; if (_random.nextBoolean()) { other = value; } else { other = _random.nextString(); } //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: assertConsistent(value, other, TextValue::startsWith); //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: assertConsistent(value, other, TextValue::endsWith); //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: assertConsistent(value, other, TextValue::contains); } }
/// <summary> /// Shuffle actions without breaking causal dependencies, i.e. without affecting the end result /// of the data ending up in the tree. Checkpoints cannot move. /// /// On an integration level with neo4j, this is done because of the nature of how concurrent transactions /// are applied in random order and recovery applies transactions in order of transaction id. /// </summary> private IList <Action> RandomCausalAwareShuffle(IList <Action> actions) { //noinspection unchecked Action[] arrayToShuffle = actions.toArray(( Action[] )Array.CreateInstance(typeof(Action), actions.Count)); int size = arrayToShuffle.Length; int numberOfActionsToShuffle = _random.Next(size / 2); for (int i = 0; i < numberOfActionsToShuffle; i++) { int actionIndexToMove = _random.Next(size); int stride = _random.nextBoolean() ? 1 : -1; int maxNumberOfSteps = _random.Next(10) + 1; for (int steps = 0; steps < maxNumberOfSteps; steps++) { Action actionToMove = arrayToShuffle[actionIndexToMove]; int actionIndexToSwap = actionIndexToMove + stride; if (actionIndexToSwap < 0 || actionIndexToSwap >= size) { break; } Action actionToSwap = arrayToShuffle[actionIndexToSwap]; if (actionToMove.HasCausalDependencyWith(actionToSwap)) { break; } arrayToShuffle[actionIndexToMove] = actionToSwap; arrayToShuffle[actionIndexToSwap] = actionToMove; actionIndexToMove = actionIndexToSwap; } } return(Arrays.asList(arrayToShuffle)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @BeforeEach void setup() internal virtual void Setup() { _layout = SimpleLongLayout.longLayout().withFixedSize(Rnd.nextBoolean()).withKeyPadding(Rnd.Next(10)).build(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setup() public virtual void Setup() { _ratioToKeepInLeftOnSplit = Random.nextBoolean() ? InternalTreeLogic.DEFAULT_SPLIT_RATIO : Random.NextDouble(); }