private void ChangeRandomNode(GraphDatabaseService db, int nodeCount, RandomValues random) { try { using (Transaction tx = Db.beginTx()) { long nodeId = random.Next(nodeCount); Node node = Db.getNodeById(nodeId); object[] keys = Iterables.asCollection(node.PropertyKeys).ToArray(); string key = ( string )random.Among(keys); if (random.NextFloat() < 0.1) { // REMOVE node.RemoveProperty(key); } else { // CHANGE node.SetProperty(key, random.NextValue().asObject()); } tx.Success(); } } catch (NotFoundException) { // It's OK, it happens if some other thread deleted that property in between us reading it and // removing or setting it } }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.List<? extends org.neo4j.kernel.api.index.IndexEntryUpdate<?>> batch() internal virtual IList <IndexEntryUpdate <object> > Batch() { int n = RandomValues.Next(MaxBatchSize) + 1; //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.List<org.neo4j.kernel.api.index.IndexEntryUpdate<?>> updates = new java.util.ArrayList<>(n); IList <IndexEntryUpdate <object> > updates = new List <IndexEntryUpdate <object> >(n); for (int i = 0; i < n; i++) { updates.Add(add(NextEntityId++, outerInstance.Descriptor, outerInstance.ValueGenerator.apply(RandomValues))); } return(updates); }
private ThreadStart Updater <T1, T2>(AtomicReferenceArray <T1> lastBatches, System.Threading.CountdownEvent insertersDone, ReadWriteLock updateLock, ICollection <T2> updates) where T1 : Org.Neo4j.Kernel.Api.Index.IndexEntryUpdate <T1> { return(throwing(() => { // Entity ids that have been removed, so that additions can reuse them IList <long> removed = new List <long>(); RandomValues randomValues = RandomValues.create(new Random(Random.seed() + THREADS)); while (insertersDone.CurrentCount > 0) { // Do updates now and then Thread.Sleep(10); updateLock.writeLock().@lock(); try { using (IndexUpdater updater = _populator.newPopulatingUpdater(_nodePropertyAccessor)) { for (int i = 0; i < THREADS; i++) { IList <IndexEntryUpdate <object> > batch = lastBatches.get(i); if (batch != null) { IndexEntryUpdate <object> update = null; switch (randomValues.Next(3)) { case 0: // add if (!removed.Empty) { long?id = removed.remove(randomValues.Next(removed.size())); update = add(id, Descriptor, ValueGenerator.apply(randomValues)); } break; case 1: // remove IndexEntryUpdate <object> removal = batch.get(randomValues.Next(batch.size())); update = remove(removal.EntityId, Descriptor, removal.values()); removed.add(removal.EntityId); break; case 2: // change removal = batch.get(randomValues.Next(batch.size())); change(removal.EntityId, Descriptor, removal.values(), toArray(ValueGenerator.apply(randomValues))); break; default: throw new System.ArgumentException(); } if (update != null) { updater.process(update); updates.Add(update); } } } } } finally { updateLock.writeLock().unlock(); } } })); }
internal override ExistingId RandomExisting(RandomValues random) { int index = random.Next(Strings.Length); return(new ExistingId(Strings[index], index)); }
internal override ExistingId RandomExisting(RandomValues random) { long index = random.Next(NODE_COUNT); return(new ExistingId(index, index)); }
internal virtual string RandomType(RandomValues random) { return("TYPE" + random.Next(RELATIONSHIP_TYPES)); }