Beispiel #1
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();
                }
            }
        }
Beispiel #2
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++;
        }
 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
     }
 }
Beispiel #4
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();
                        }
                    }
                }
            }
Beispiel #5
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();
                }
            }
        }
        public override void CreateTestGraph(GraphDatabaseService graphDb)
        {
            using (Transaction tx = graphDb.BeginTx())
            {
                graphDb.Schema().indexFor(label("Node")).on("prop").create();
                graphDb.Schema().indexFor(label("Node")).on("prop").on("prip").create();
                tx.Success();
            }
            using (Transaction tx = graphDb.BeginTx())
            {
                graphDb.Schema().awaitIndexesOnline(5, MINUTES);
                tx.Success();
            }

            using (Transaction tx = graphDb.BeginTx())
            {
                RandomValues randomValues = RandomRule.randomValues();

                ValueType[] allExceptNonSortable = RandomValues.excluding(ValueType.STRING, ValueType.STRING_ARRAY);

                for (int i = 0; i < _nNodes; i++)
                {
                    Node  node      = graphDb.CreateNode(label("Node"));
                    Value propValue = randomValues.NextValueOfTypes(allExceptNonSortable);
                    node.SetProperty("prop", propValue.AsObject());
                    Value pripValue = randomValues.NextValue();
                    node.SetProperty("prip", pripValue.AsObject());

                    _singlePropValues.Add(propValue);
                    _doublePropValues.Add(ValueTuple.of(propValue, pripValue));
                }
                tx.Success();
            }

            _singlePropValues.sort(Values.COMPARATOR);
            _doublePropValues.sort(ValueTuple.COMPARATOR);
        }
Beispiel #7
0
        private ISet <Value> RandomValues()
        {
            RandomValues randoms = RandomValues.create(new ArraySizeConfig(5, 100));

            return(IntStream.range(0, _nodesToCreate).mapToObj(i => randoms.NextValue()).collect(toSet()));
        }
Beispiel #8
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());
        }
Beispiel #9
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);
            }
        }