Пример #1
0
        protected internal override void DoWork()
        {
            _txLogger.info("SuccessCount: " + _txSuccessCount + " FailCount: " + _txFailCount);
            RandomValues randomValues = RandomValues.create();

            try
            {
                _cluster.coreTx((db, tx) =>
                {
                    Node node = Db.createNode(_label);
                    for (int i = 1; i <= 8; i++)
                    {
                        node.setProperty(Prop(i), randomValues.NextValue().asObject());
                    }
                    tx.success();
                });
            }
            catch (Exception e)
            {
                _txFailCount++;

                if (IsInterrupted(e) || IsTransient(e))
                {
                    // whatever let's go on with the workload
                    return;
                }

                throw new Exception(e);
            }

            _txSuccessCount++;
        }
Пример #2
0
        private static void CreateDatabaseWithNativeIndexes(File databaseDirectory)
        {
            // Create one index for every provider that we have
            foreach (SchemaIndex schemaIndex in SchemaIndex.values())
            {
                GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(databaseDirectory).setConfig(default_schema_provider, schemaIndex.providerName()).newGraphDatabase();
                string key = "key-" + schemaIndex.name();
                try
                {
                    Label labelOne = Label.label("one");
                    using (Transaction tx = Db.beginTx())
                    {
                        Db.schema().indexFor(labelOne).on(key).create();
                        tx.Success();
                    }

                    using (Transaction tx = Db.beginTx())
                    {
                        RandomValues randomValues = RandomValues.create();
                        for (int i = 0; i < 10_000; i++)
                        {
                            Db.createNode(labelOne).setProperty(key, randomValues.NextValue().asObject());
                        }
                        tx.Success();
                    }
                }
                finally
                {
                    Db.shutdown();
                }
            }
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void consistencyCheckerMustBeAbleToRunOnStoreWithFulltextIndexes() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ConsistencyCheckerMustBeAbleToRunOnStoreWithFulltextIndexes()
        {
            GraphDatabaseService db = CreateDatabase();

//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            Label[] labels = IntStream.range(1, 7).mapToObj(i => Label.label("LABEL" + i)).toArray(Label[] ::new);
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            RelationshipType[] relTypes = IntStream.range(1, 5).mapToObj(i => RelationshipType.withName("REL" + i)).toArray(RelationshipType[] ::new);
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            string[]     propertyKeys = IntStream.range(1, 7).mapToObj(i => "PROP" + i).toArray(string[] ::new);
            RandomValues randomValues = RandomValues.create();

            using (Transaction tx = Db.beginTx())
            {
                ThreadLocalRandom rng  = ThreadLocalRandom.current();
                int          nodeCount = 1000;
                IList <Node> nodes     = new List <Node>(nodeCount);
                for (int i = 0; i < nodeCount; i++)
                {
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
                    Label[] nodeLabels = rng.ints(rng.Next(labels.Length), 0, labels.Length).distinct().mapToObj(x => labels[x]).toArray(Label[] ::new);
                    Node    node       = Db.createNode(nodeLabels);
                    Stream.of(propertyKeys).forEach(p => node.setProperty(p, rng.nextBoolean() ? p : randomValues.NextValue().asObject()));
                    nodes.Add(node);
                    int localRelCount = Math.Min(nodes.Count, 5);
                    rng.ints(localRelCount, 0, localRelCount).distinct().mapToObj(x => node.CreateRelationshipTo(nodes[x], relTypes[rng.Next(relTypes.Length)])).forEach(r => Stream.of(propertyKeys).forEach(p => r.setProperty(p, rng.nextBoolean() ? p : randomValues.NextValue().asObject())));
                }
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                for (int i = 1; i < labels.Length; i++)
                {
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
                    Db.execute(format(NODE_CREATE, "nodes" + i, array(java.util.labels.Take(i).Select(Label::name).ToArray(string[] ::new)), array(Arrays.copyOf(propertyKeys, i)))).close();
                }
                for (int i = 1; i < relTypes.Length; i++)
                {
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
                    Db.execute(format(RELATIONSHIP_CREATE, "rels" + i, array(java.util.relTypes.Take(i).Select(RelationshipType::name).ToArray(string[] ::new)), array(Arrays.copyOf(propertyKeys, i)))).close();
                }
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                Db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
                tx.Success();
            }

            Db.shutdown();

            AssertIsConsistent(CheckConsistency());
        }
Пример #4
0
        private void PrePopulateDatabase(GraphDatabaseService database, Label testLabel, string propertyName)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.values.storable.RandomValues randomValues = org.neo4j.values.storable.RandomValues.create();
            RandomValues randomValues = RandomValues.create();

            for (int j = 0; j < 10_000; j++)
            {
                using (Transaction transaction = database.BeginTx())
                {
                    Node   node     = database.CreateNode(testLabel);
                    object property = randomValues.NextValue().asObject();
                    node.SetProperty(propertyName, property);
                    transaction.Success();
                }
            }
        }
Пример #5
0
            public override void Run()
            {
                RandomValues randomValues = RandomValues.create();

                awaitLatch(StartSignal);
                while (!EndSignal.get())
                {
                    using (Transaction transaction = DatabaseService.beginTx())
                    {
                        try
                        {
                            int operationType = randomValues.NextIntValue(3).value();
                            switch (operationType)
                            {
                            case 0:
                                long targetNodeId = randomValues.NextLongValue(TotalNodes).value();
                                DatabaseService.getNodeById(targetNodeId).delete();
                                break;

                            case 1:
                                long nodeId = randomValues.NextLongValue(TotalNodes).value();
                                Node node   = DatabaseService.getNodeById(nodeId);
                                IDictionary <string, object> allProperties = node.AllProperties;
                                foreach (string key in allProperties.Keys)
                                {
                                    node.SetProperty(key, randomValues.NextValue().asObject());
                                }
                                break;

                            case 2:
                                Node nodeToUpdate = DatabaseService.createNode(Label.label("label10"));
                                nodeToUpdate.SetProperty("property", randomValues.NextValue().asObject());
                                break;

                            default:
                                throw new System.NotSupportedException("Unknown type of index operation");
                            }
                            transaction.Success();
                        }
                        catch (Exception)
                        {
                            transaction.Failure();
                        }
                    }
                }
            }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void populateDbAndIndexes(int nodeCount, boolean multiThreaded) throws InterruptedException
        private void PopulateDbAndIndexes(int nodeCount, bool multiThreaded)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.GraphDatabaseService db = new org.neo4j.test.TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(directory.databaseDir()).setConfig(org.neo4j.graphdb.factory.GraphDatabaseSettings.multi_threaded_schema_index_population_enabled, multiThreaded + "").newGraphDatabase();
            GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(_directory.databaseDir()).setConfig(GraphDatabaseSettings.multi_threaded_schema_index_population_enabled, multiThreaded + "").newGraphDatabase();

            try
            {
                CreateIndexes(db);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean();
                AtomicBoolean   end      = new AtomicBoolean();
                ExecutorService executor = _cleanup.add(Executors.newCachedThreadPool());
                for (int i = 0; i < 10; i++)
                {
                    executor.submit(() =>
                    {
                        RandomValues randomValues = RandomValues.create();
                        while (!end.get())
                        {
                            ChangeRandomNode(db, nodeCount, randomValues);
                        }
                    });
                }

                while (!IndexesAreOnline(db))
                {
                    Thread.Sleep(100);
                }
                end.set(true);
                executor.shutdown();
                executor.awaitTermination(10, SECONDS);
            }
            finally
            {
                Db.shutdown();
            }
        }
Пример #7
0
 internal virtual void Reset()
 {
     RandomValues = RandomValues.create(new Random(Seed));
     NextEntityId = StartEntityId;
 }
Пример #8
0
        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();
                    }
                }
            }));
        }
Пример #9
0
        private ISet <Value> RandomValues()
        {
            RandomValues randoms = RandomValues.create(new ArraySizeConfig(5, 100));

            return(IntStream.range(0, _nodesToCreate).mapToObj(i => randoms.NextValue()).collect(toSet()));
        }
Пример #10
0
        private ISet <Value> RandomArrays(int minLength, int maxLength)
        {
            RandomValues randoms = RandomValues.create(new ArraySizeConfig(minLength, maxLength));

            return(IntStream.range(0, _nodesToCreate).mapToObj(i => randoms.NextArray()).collect(toSet()));
        }
Пример #11
0
        // ============================
        // Other utility methods
        // ============================

        public virtual void Reset()
        {
            _random  = new Random(_seed);
            _randoms = RandomValues.create(_random, _config);
        }
Пример #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void populateDbWithConcurrentUpdates() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void PopulateDbWithConcurrentUpdates()
        {
            GraphDatabaseService database = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(_testDirectory.databaseDir());

            try
            {
                RandomValues randomValues = RandomValues.create();
                int          counter      = 1;
                for (int j = 0; j < 100; j++)
                {
                    using (Transaction transaction = database.BeginTx())
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            Node node = database.CreateNode(Label.label("label" + counter));
                            node.SetProperty("property", randomValues.NextValue().asObject());
                        }
                        transaction.Success();
                    }
                    counter++;
                }

                int             populatorCount = 5;
                ExecutorService executor       = Executors.newFixedThreadPool(populatorCount);
                System.Threading.CountdownEvent startSignal = new System.Threading.CountdownEvent(1);
                AtomicBoolean endSignal = new AtomicBoolean();
                for (int i = 0; i < populatorCount; i++)
                {
                    executor.submit(new Populator(this, database, counter, startSignal, endSignal));
                }

                try
                {
                    using (Transaction transaction = database.BeginTx())
                    {
                        database.Schema().indexFor(Label.label("label10")).on("property").create();
                        transaction.Success();
                    }
                    startSignal.Signal();

                    using (Transaction transaction = database.BeginTx())
                    {
                        database.Schema().awaitIndexesOnline(populatorCount, TimeUnit.MINUTES);
                        transaction.Success();
                    }
                }
                finally
                {
                    endSignal.set(true);
                    executor.shutdown();
                    // Basically we don't care to await their completion because they've done their job
                }
            }
            finally
            {
                database.Shutdown();
                ConsistencyCheckService consistencyCheckService = new ConsistencyCheckService();
                Config config = Config.defaults(GraphDatabaseSettings.pagecache_memory, "8m");
                consistencyCheckService.RunFullConsistencyCheck(_testDirectory.databaseLayout(), config, ProgressMonitorFactory.NONE, FormattedLogProvider.toOutputStream(System.out), false);
            }
        }