Esempio n. 1
0
        private static void CreateIndexes(GraphDatabaseService database, string propertyName, Label testLabel)
        {
            using (Transaction transaction = database.BeginTx())
            {
                database.Schema().indexFor(testLabel).on(propertyName).create();
                transaction.Success();
            }

            using (Transaction ignored = database.BeginTx())
            {
                database.Schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
            }
        }
Esempio n. 2
0
 private IList <ConstraintDefinition> Constraints(GraphDatabaseService database)
 {
     using (Transaction ignored = database.BeginTx())
     {
         return(Iterables.asList(database.Schema().Constraints));
     }
 }
Esempio n. 3
0
 private IList <IndexDefinition> Indexes(GraphDatabaseService database)
 {
     using (Transaction ignored = database.BeginTx())
     {
         return(Iterables.asList(database.Schema().Indexes));
     }
 }
Esempio n. 4
0
        private static void CreateIndex(GraphDatabaseService gds, Label label, string propKey)
        {
            IndexDefinition indexDefinition;

            using (Transaction tx = gds.BeginTx())
            {
                indexDefinition = gds.Schema().indexFor(label).on(propKey).create();
                tx.Success();
            }

            using (Transaction tx = gds.BeginTx())
            {
                gds.Schema().awaitIndexOnline(indexDefinition, 1, TimeUnit.MINUTES);
                tx.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();
            }

            RandomValues randomValues = RandomRule.randomValues();

            ValueType[] allExceptNonOrderable = RandomValues.excluding(ValueType.STRING, ValueType.STRING_ARRAY, ValueType.GEOGRAPHIC_POINT, ValueType.GEOGRAPHIC_POINT_ARRAY, ValueType.GEOGRAPHIC_POINT_3D, ValueType.GEOGRAPHIC_POINT_3D_ARRAY, ValueType.CARTESIAN_POINT, ValueType.CARTESIAN_POINT_ARRAY, ValueType.CARTESIAN_POINT_3D, ValueType.CARTESIAN_POINT_3D_ARRAY);
            _targetedTypes = randomValues.Selection(allExceptNonOrderable, 1, allExceptNonOrderable.Length, false);
            _targetedTypes = EnsureHighEnoughCardinality(_targetedTypes);
            using (Transaction tx = graphDb.BeginTx())
            {
                for (int i = 0; i < _nNodes; i++)
                {
                    Node           node = graphDb.CreateNode(label("Node"));
                    Value          propValue;
                    Value          pripValue;
                    NodeValueTuple singleValue;
                    NodeValueTuple doubleValue;
                    do
                    {
                        propValue   = randomValues.NextValueOfTypes(_targetedTypes);
                        pripValue   = randomValues.NextValueOfTypes(_targetedTypes);
                        singleValue = new NodeValueTuple(this, node.Id, propValue);
                        doubleValue = new NodeValueTuple(this, node.Id, propValue, pripValue);
                    } while (_singlePropValues.Contains(singleValue) || _doublePropValues.Contains(doubleValue));
                    _singlePropValues.Add(singleValue);
                    _doublePropValues.Add(doubleValue);

                    node.SetProperty("prop", propValue.AsObject());
                    node.SetProperty("prip", pripValue.AsObject());
                }
                tx.Success();
            }
        }
Esempio n. 6
0
        public static SubGraph From(Result result, GraphDatabaseService gds, bool addBetween)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final CypherResultSubGraph graph = new CypherResultSubGraph();
            CypherResultSubGraph graph = new CypherResultSubGraph();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<String> columns = result.columns();
            IList <string> columns = result.Columns();

            foreach (IDictionary <string, object> row in loop(result))
            {
                foreach (string column in columns)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Object value = row.get(column);
                    object value = row[column];
                    graph.AddToGraph(value);
                }
            }
            foreach (IndexDefinition def in gds.Schema().Indexes)
            {
                foreach (Label label in def.Labels)
                {
                    if (graph.Labels.Contains(label))
                    {
                        graph.AddIndex(def);
                        break;
                    }
                }
            }
            foreach (ConstraintDefinition def in gds.Schema().Constraints)
            {
                if (graph.Labels.Contains(def.Label))
                {
                    graph.AddConstraint(def);
                }
            }
            if (addBetween)
            {
                graph.AddRelationshipsBetweenNodes();
            }
            return(graph);
        }
Esempio n. 7
0
 private static void DropAllIndexes(GraphDatabaseService database)
 {
     using (Transaction transaction = database.BeginTx())
     {
         foreach (IndexDefinition definition in database.Schema().Indexes)
         {
             definition.Drop();
         }
         transaction.Success();
     }
 }
Esempio n. 8
0
            protected internal override void Startup(File storeDir)
            {
                GraphDatabaseService database = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(storeDir);

                using (Transaction transaction = database.BeginTx())
                {
                    database.Schema().constraintFor(label("User")).assertPropertyIsUnique("uuid").create();
                    transaction.Success();
                }
                Started = true;
            }
        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);
        }
Esempio n. 10
0
 private static void WaitForIndexPopulationFailure(GraphDatabaseService database)
 {
     try
     {
         using (Transaction ignored = database.BeginTx())
         {
             database.Schema().awaitIndexesOnline(10, TimeUnit.MINUTES);
             fail("Unique index population should fail.");
         }
     }
     catch (System.InvalidOperationException)
     {
         // TODO: Do we really need to verify the message since we know an IllegalStateException was caught? If so, this needs to be updated.
         // assertEquals( "Index entered a FAILED state. Please see database logs.", e.getMessage() );
     }
 }
Esempio n. 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shutdownDatabaseDuringIndexPopulations()
        public virtual void ShutdownDatabaseDuringIndexPopulations()
        {
            AssertableLogProvider assertableLogProvider = new AssertableLogProvider(true);
            File   storeDir                 = Directory.directory("shutdownDbTest");
            Label  testLabel                = Label.label("testLabel");
            string propertyName             = "testProperty";
            GraphDatabaseService shutDownDb = (new TestGraphDatabaseFactory()).setInternalLogProvider(assertableLogProvider).newEmbeddedDatabase(storeDir);

            PrePopulateDatabase(shutDownDb, testLabel, propertyName);

            using (Transaction transaction = shutDownDb.BeginTx())
            {
                shutDownDb.Schema().indexFor(testLabel).on(propertyName).create();
                transaction.Success();
            }
            shutDownDb.Shutdown();
            assertableLogProvider.AssertNone(AssertableLogProvider.inLog(typeof(IndexPopulationJob)).anyError());
        }
Esempio n. 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);
            }
        }
 protected internal override Schema ObtainEntityInTransaction(GraphDatabaseService graphDatabaseService)
 {
     return(graphDatabaseService.Schema());
 }
Esempio n. 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMigrate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldMigrate()
        {
            DatabaseLayout       databaseLayout = _testDir.databaseLayout(BaseDirName(To, From));
            GraphDatabaseService database       = GetGraphDatabaseService(databaseLayout.DatabaseDirectory(), From.storeVersion());

            database.Execute("CREATE INDEX ON :Person(name)");
            database.Execute("CREATE INDEX ON :Person(born)");
            database.Execute("CREATE CONSTRAINT ON (person:Person) ASSERT exists(person.name)");
            database.Execute(CreateQuery);
            long beforeNodes;
            long beforeLabels;
            long beforeKeys;
            long beforeRels;
            long beforeRelTypes;
            long beforeIndexes;
            long beforeConstraints;

            using (Transaction ignore = database.BeginTx())
            {
                beforeNodes       = database.AllNodes.Count();
                beforeLabels      = database.AllLabels.Count();
                beforeKeys        = database.AllPropertyKeys.Count();
                beforeRels        = database.AllRelationships.Count();
                beforeRelTypes    = database.AllRelationshipTypes.Count();
                beforeIndexes     = Stream(database.Schema().Indexes).count();
                beforeConstraints = Stream(database.Schema().Constraints).count();
            }
            database.Shutdown();

            database = GetGraphDatabaseService(databaseLayout.DatabaseDirectory(), To.storeVersion());
            long afterNodes;
            long afterLabels;
            long afterKeys;
            long afterRels;
            long afterRelTypes;
            long afterIndexes;
            long afterConstraints;

            using (Transaction ignore = database.BeginTx())
            {
                afterNodes       = database.AllNodes.Count();
                afterLabels      = database.AllLabels.Count();
                afterKeys        = database.AllPropertyKeys.Count();
                afterRels        = database.AllRelationships.Count();
                afterRelTypes    = database.AllRelationshipTypes.Count();
                afterIndexes     = Stream(database.Schema().Indexes).count();
                afterConstraints = Stream(database.Schema().Constraints).count();
            }
            database.Shutdown();

            assertEquals(beforeNodes, afterNodes);               //171
            assertEquals(beforeLabels, afterLabels);             //2
            assertEquals(beforeKeys, afterKeys);                 //8
            assertEquals(beforeRels, afterRels);                 //253
            assertEquals(beforeRelTypes, afterRelTypes);         //6
            assertEquals(beforeIndexes, afterIndexes);           //2
            assertEquals(beforeConstraints, afterConstraints);   //1
            ConsistencyCheckService consistencyCheckService = new ConsistencyCheckService();

            ConsistencyCheckService.Result result = RunConsistencyChecker(databaseLayout, _fileSystemRule.get(), consistencyCheckService, To.storeVersion());
            if (!result.Successful)
            {
                fail("Database is inconsistent after migration.");
            }
        }
Esempio n. 15
0
 protected internal override IndexCreator ObtainEntityInTransaction(GraphDatabaseService graphDatabaseService)
 {
     return(graphDatabaseService.Schema().indexFor(Label.label("Label")));
 }
Esempio n. 16
0
 protected internal override ConstraintDefinition ObtainEntityInTransaction(GraphDatabaseService graphDatabaseService)
 {
     return(graphDatabaseService.Schema().constraintFor(Label.label("Label")).assertPropertyIsUnique("property").create());
 }
 protected internal override IndexDefinition ObtainEntityInTransaction(GraphDatabaseService graphDatabaseService)
 {
     return(graphDatabaseService.Schema().indexFor(Label.label("Label")).on("property").create());
 }