示例#1
0
        public override void CreateTestGraph(GraphDatabaseService graphDb)
        {
            IList <Node> deleted = new List <Node>();

            using (Transaction tx = graphDb.BeginTx())
            {
                for (int i = 0; i < _nNodes; i++)
                {
                    Node node = graphDb.CreateNode();
                    if (_random.nextBoolean())
                    {
                        _nodeIds.Add(node.Id);
                    }
                    else
                    {
                        deleted.Add(node);
                    }
                }
                tx.Success();
            }

            using (Transaction tx = graphDb.BeginTx())
            {
                foreach (Node node in deleted)
                {
                    node.Delete();
                }
                tx.Success();
            }
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowWhenMultipleResultsForSingleNode()
        public virtual void ShouldThrowWhenMultipleResultsForSingleNode()
        {
            // given
            GraphDatabaseService graph = DbRule.GraphDatabaseAPI;

            Neo4jMatchers.createIndex(graph, _label1, "name");

            Node node1;
            Node node2;

            using (Transaction tx = graph.BeginTx())
            {
                node1 = graph.CreateNode(_label1);
                node1.SetProperty("name", "Stefan");

                node2 = graph.CreateNode(_label1);
                node2.SetProperty("name", "Stefan");
                tx.Success();
            }

            try
            {
                using (Transaction tx = graph.BeginTx())
                {
                    graph.FindNode(_label1, "name", "Stefan");
                    fail("Expected MultipleFoundException but got none");
                }
            }
            catch (MultipleFoundException e)
            {
                assertThat(e.Message, equalTo(format("Found multiple nodes with label: '%s', property name: 'name' " + "and property value: 'Stefan' while only one was expected.", _label1)));
            }
        }
示例#3
0
        public override void CreateTestGraph(GraphDatabaseService graphDb)
        {
            Node deleted;

            using (Transaction tx = graphDb.BeginTx())
            {
                _foo    = graphDb.CreateNode(label("Foo")).Id;
                _bar    = graphDb.CreateNode(label("Bar")).Id;
                _baz    = graphDb.CreateNode(label("Baz")).Id;
                _barbaz = graphDb.CreateNode(label("Bar"), label("Baz")).Id;
                _gone   = (deleted = graphDb.CreateNode()).Id;
                _bare   = graphDb.CreateNode().Id;

                tx.Success();
            }

            using (Transaction tx = graphDb.BeginTx())
            {
                deleted.Delete();

                tx.Success();
            }

            using (Transaction tx = graphDb.BeginTx())
            {
                _nodeIds = new List <long>();
                foreach (Node node in graphDb.AllNodes)
                {
                    _nodeIds.Add(node.Id);
                }
                tx.Success();
            }
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void addingALabelUsingAnInvalidIdentifierShouldFail()
        public virtual void AddingALabelUsingAnInvalidIdentifierShouldFail()
        {
            // Given
            GraphDatabaseService graphDatabase = DbRule.GraphDatabaseAPI;

            // When I set an empty label
            try
            {
                using (Transaction ignored = graphDatabase.BeginTx())
                {
                    graphDatabase.CreateNode().addLabel(label(""));
                    fail("Should have thrown exception");
                }
            }
            catch (ConstraintViolationException)
            {               // Happy
            }

            // And When I set a null label
            try
            {
                using (Transaction ignored = graphDatabase.BeginTx())
                {
                    graphDatabase.CreateNode().addLabel(() => null);
                    fail("Should have thrown exception");
                }
            }
            catch (ConstraintViolationException)
            {               // Happy
            }
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRetrieveMultipleNodesWithSameValueFromIndex()
        public virtual void ShouldRetrieveMultipleNodesWithSameValueFromIndex()
        {
            // this test was included here for now as a precondition for the following test

            // given
            GraphDatabaseService graph = DbRule.GraphDatabaseAPI;

            Neo4jMatchers.createIndex(graph, _label1, "name");

            Node node1;
            Node node2;

            using (Transaction tx = graph.BeginTx())
            {
                node1 = graph.CreateNode(_label1);
                node1.SetProperty("name", "Stefan");

                node2 = graph.CreateNode(_label1);
                node2.SetProperty("name", "Stefan");
                tx.Success();
            }

            using (Transaction tx = graph.BeginTx())
            {
                ResourceIterator <Node> result = graph.FindNodes(_label1, "name", "Stefan");
                assertEquals(asSet(node1, node2), asSet(result));

                tx.Success();
            }
        }
示例#6
0
        public virtual void PutRelationshipIfAbsentOnlyFail()
        {
            // Given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String index = indexes.newInstance();
            string index = _indexes.newInstance();
            string key   = "name";
            string value = "Peter";
            GraphDatabaseService graphdb = graphdb();

            _helper.createRelationshipIndex(index);
            using (Transaction tx = graphdb.BeginTx())
            {
                Node         node1 = graphdb.CreateNode();
                Node         node2 = graphdb.CreateNode();
                Relationship rel   = node1.CreateRelationshipTo(node2, MyRelationshipTypes.Knows);
                graphdb.Index().forRelationships(index).add(rel, key, value);
                tx.Success();
            }

            Relationship rel;

            using (Transaction tx = graphdb.BeginTx())
            {
                Node node1 = graphdb.CreateNode();
                Node node2 = graphdb.CreateNode();
                rel = node1.CreateRelationshipTo(node2, MyRelationshipTypes.Knows);
                tx.Success();
            }

            // When & Then
            GenConflict.get().expectedStatus(409).payloadType(MediaType.APPLICATION_JSON_TYPE).payload("{\"key\": \"" + key + "\", \"value\": \"" + value + "\", \"uri\":\"" + _functionalTestHelper.relationshipUri(rel.Id) + "\"}").post(_functionalTestHelper.relationshipIndexUri() + index + "?uniqueness=create_or_fail");
        }
示例#7
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);
            }
        }
示例#8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void providerGetsFilledInAutomatically()
		 public virtual void ProviderGetsFilledInAutomatically()
		 {
			  IDictionary<string, string> correctConfig = MapUtil.stringMap( "type", "exact", Org.Neo4j.Graphdb.index.IndexManager_Fields.PROVIDER, "lucene" );
			  File storeDir = TestDirectory.storeDir();
			  Neo4jTestCase.deleteFileOrDirectory( storeDir );
			  GraphDatabaseService graphDb = StartDatabase( storeDir );
			  using ( Transaction transaction = graphDb.BeginTx() )
			  {
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("default")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("wo-provider", MapUtil.stringMap("type", "exact"))) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("w-provider", MapUtil.stringMap("type", "exact", Org.Neo4j.Graphdb.index.IndexManager_Fields.PROVIDER, "lucene"))) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("default")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("wo-provider", MapUtil.stringMap("type", "exact"))) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("w-provider", MapUtil.stringMap("type", "exact", Org.Neo4j.Graphdb.index.IndexManager_Fields.PROVIDER, "lucene"))) );
					transaction.Success();
			  }

			  graphDb.Shutdown();

			  RemoveProvidersFromIndexDbFile( TestDirectory.databaseLayout() );
			  graphDb = StartDatabase( storeDir );

			  using ( Transaction ignored = graphDb.BeginTx() )
			  {
					// Getting the index w/o exception means that the provider has been reinstated
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("default")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("wo-provider", MapUtil.stringMap("type", "exact"))) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("w-provider", MapUtil.stringMap("type", "exact", Org.Neo4j.Graphdb.index.IndexManager_Fields.PROVIDER, "lucene"))) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("default")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("wo-provider", MapUtil.stringMap("type", "exact"))) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("w-provider", MapUtil.stringMap("type", "exact", Org.Neo4j.Graphdb.index.IndexManager_Fields.PROVIDER, "lucene"))) );
			  }

			  graphDb.Shutdown();

			  RemoveProvidersFromIndexDbFile( TestDirectory.databaseLayout() );
			  graphDb = StartDatabase( storeDir );

			  using ( Transaction ignored = graphDb.BeginTx() )
			  {
					// Getting the index w/o exception means that the provider has been reinstated
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("default")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("wo-provider")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forNodes("w-provider")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("default")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("wo-provider")) );
					assertEquals( correctConfig, graphDb.Index().getConfiguration(graphDb.Index().forRelationships("w-provider")) );
			  }

			  graphDb.Shutdown();
		 }
示例#9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void restoreExplicitIndexesFromBackup() throws java.io.IOException, org.neo4j.commandline.admin.CommandFailed
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RestoreExplicitIndexesFromBackup()
        {
            string databaseName = "destination";
            Config config       = ConfigWith(databaseName, Directory.absolutePath().AbsolutePath);
            File   fromPath     = new File(Directory.absolutePath(), "from");
            File   toPath       = config.Get(GraphDatabaseSettings.database_path);

            CreateDbWithExplicitIndexAt(fromPath, 100);

            (new RestoreDatabaseCommand(FileSystemRule.get(), fromPath, config, databaseName, true)).execute();

            GraphDatabaseService restoredDatabase = CreateDatabase(toPath, toPath.AbsolutePath);

            using (Transaction transaction = restoredDatabase.BeginTx())
            {
                IndexManager indexManager           = restoredDatabase.Index();
                string[]     nodeIndexNames         = indexManager.NodeIndexNames();
                string[]     relationshipIndexNames = indexManager.RelationshipIndexNames();

                foreach (string nodeIndexName in nodeIndexNames)
                {
                    CountNodesByKeyValue(indexManager, nodeIndexName, "a", "b");
                    CountNodesByKeyValue(indexManager, nodeIndexName, "c", "d");
                }

                foreach (string relationshipIndexName in relationshipIndexNames)
                {
                    CountRelationshipByKeyValue(indexManager, relationshipIndexName, "x", "y");
                }
            }
            restoredDatabase.Shutdown();
        }
示例#10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowForcedCopyOverAnExistingDatabase() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowForcedCopyOverAnExistingDatabase()
        {
            // given
            string databaseName = "to";
            Config config       = ConfigWith(databaseName, Directory.absolutePath().AbsolutePath);

            File fromPath      = new File(Directory.absolutePath(), "from");
            File toPath        = config.Get(GraphDatabaseSettings.database_path);
            int  fromNodeCount = 10;
            int  toNodeCount   = 20;

            CreateDbAt(fromPath, fromNodeCount);
            CreateDbAt(toPath, toNodeCount);

            // when
            (new RestoreDatabaseCommand(FileSystemRule.get(), fromPath, config, databaseName, true)).execute();

            // then
            GraphDatabaseService copiedDb = (new GraphDatabaseFactory()).newEmbeddedDatabaseBuilder(toPath).setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase();

            using (Transaction ignored = copiedDb.BeginTx())
            {
                assertEquals(fromNodeCount, Iterables.count(copiedDb.AllNodes));
            }

            copiedDb.Shutdown();
        }
示例#11
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();
            }
        }
示例#12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void createDateArrayOnLatestDatabase()
        internal virtual void CreateDateArrayOnLatestDatabase()
        {
            File      storeDir    = _testDirectory.storeDir();
            Label     label       = Label.label("DateNode");
            string    propertyKey = "a";
            LocalDate date        = DateValue.date(1991, 5, 3).asObjectCopy();

            GraphDatabaseService database = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode(label);
                node.SetProperty(propertyKey, new LocalDate[] { date, date });
                transaction.Success();
            }
            database.Shutdown();

            GraphDatabaseService restartedDatabase = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction ignored = restartedDatabase.BeginTx())
            {
                using (ResourceIterator <Node> nodes = restartedDatabase.FindNodes(label))
                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    Node        node   = nodes.next();
                    LocalDate[] points = ( LocalDate[] )node.GetProperty(propertyKey);
                    assertThat(points, arrayWithSize(2));
                }
            }
            restartedDatabase.Shutdown();
        }
示例#13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void createDatePropertyOnLatestDatabase()
        internal virtual void CreateDatePropertyOnLatestDatabase()
        {
            File      storeDir    = _testDirectory.storeDir();
            Label     label       = Label.label("DateNode");
            string    propertyKey = "a";
            LocalDate date        = DateValue.date(1991, 5, 3).asObjectCopy();

            GraphDatabaseService database = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode(label);
                node.SetProperty(propertyKey, date);
                transaction.Success();
            }
            database.Shutdown();

            GraphDatabaseService restartedDatabase = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction ignored = restartedDatabase.BeginTx())
            {
                assertNotNull(restartedDatabase.FindNode(label, propertyKey, date));
            }
            restartedDatabase.Shutdown();
        }
示例#14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void failToCreateDateArrayOnOldDatabase()
        internal virtual void FailToCreateDateArrayOnOldDatabase()
        {
            File storeDir = _testDirectory.storeDir();
            GraphDatabaseService        nonUpgradedStore = startNonUpgradableDatabaseWithFormat(storeDir, StandardV3_2.NAME);
            LocalDate                   date             = DateValue.date(1991, 5, 3).asObjectCopy();
            TransactionFailureException failureException = assertThrows(typeof(TransactionFailureException), () =>
            {
                using (Transaction transaction = nonUpgradedStore.BeginTx())
                {
                    Node node = nonUpgradedStore.CreateNode();
                    node.setProperty("a", new LocalDate[] { date, date });
                    transaction.success();
                }
            });

            assertEquals("Current record format does not support TEMPORAL_PROPERTIES. Please upgrade your store " + "to the format that support requested capability.", Exceptions.rootCause(failureException).Message);
            nonUpgradedStore.Shutdown();

            GraphDatabaseService restartedOldFormatDatabase = startNonUpgradableDatabaseWithFormat(storeDir, StandardV3_2.NAME);

            using (Transaction transaction = restartedOldFormatDatabase.BeginTx())
            {
                Node node = restartedOldFormatDatabase.CreateNode();
                node.SetProperty("c", "d");
                transaction.success();
            }
            restartedOldFormatDatabase.Shutdown();
        }
示例#15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCorrectlyUpdateIndexesWhenChangingLabelsAndPropertyAtTheSameTime()
        public virtual void ShouldCorrectlyUpdateIndexesWhenChangingLabelsAndPropertyAtTheSameTime()
        {
            // Given
            GraphDatabaseService beansAPI = DbRule.GraphDatabaseAPI;
            Node myNode = CreateNode(beansAPI, map("name", "Hawking"), _label1, _label2);

            Neo4jMatchers.createIndex(beansAPI, _label1, "name");
            Neo4jMatchers.createIndex(beansAPI, _label2, "name");
            Neo4jMatchers.createIndex(beansAPI, _label3, "name");

            // When
            using (Transaction tx = beansAPI.BeginTx())
            {
                myNode.RemoveLabel(_label1);
                myNode.AddLabel(_label3);
                myNode.SetProperty("name", "Einstein");
                tx.Success();
            }

            // Then
            assertThat(myNode, inTx(beansAPI, hasProperty("name").withValue("Einstein")));
            assertThat(Labels(myNode), containsOnly(_label2, _label3));

            assertThat(findNodesByLabelAndProperty(_label1, "name", "Hawking", beansAPI), Empty);
            assertThat(findNodesByLabelAndProperty(_label1, "name", "Einstein", beansAPI), Empty);

            assertThat(findNodesByLabelAndProperty(_label2, "name", "Hawking", beansAPI), Empty);
            assertThat(findNodesByLabelAndProperty(_label2, "name", "Einstein", beansAPI), containsOnly(myNode));

            assertThat(findNodesByLabelAndProperty(_label3, "name", "Hawking", beansAPI), Empty);
            assertThat(findNodesByLabelAndProperty(_label3, "name", "Einstein", beansAPI), containsOnly(myNode));
        }
示例#16
0
        internal static StartNode Dense(GraphDatabaseService graphDb)
        {
            Node node;
            IDictionary <string, IList <StartRelationship> > relationshipMap;

            using (Transaction tx = graphDb.BeginTx())
            {
                node            = graphDb.CreateNode();
                relationshipMap = BuildSparseDenseRels(node);

                IList <StartRelationship> bulk     = new List <StartRelationship>();
                RelationshipType          bulkType = withName("BULK");

                for (int i = 0; i < 200; i++)
                {
                    Relationship r = node.CreateRelationshipTo(graphDb.CreateNode(), bulkType);
                    bulk.Add(new StartRelationship(r.Id, Direction.OUTGOING, bulkType));
                }

                string bulkKey = ComputeKey("BULK", Direction.OUTGOING);
                relationshipMap[bulkKey] = bulk;

                tx.Success();
            }
            return(new StartNode(node.Id, relationshipMap));
        }
示例#17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldUseConcurrentlyCreatedNode()
        internal virtual void ShouldUseConcurrentlyCreatedNode()
        {
            // given
            GraphDatabaseService graphdb = mock(typeof(GraphDatabaseService));
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") Index<org.neo4j.graphdb.Node> index = mock(Index.class);
            Index <Node> index = mock(typeof(Index));
            Transaction  tx    = mock(typeof(Transaction));

            when(graphdb.BeginTx()).thenReturn(tx);
            when(index.GraphDatabase).thenReturn(graphdb);
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") IndexHits<org.neo4j.graphdb.Node> getHits = mock(IndexHits.class);
            IndexHits <Node> getHits = mock(typeof(IndexHits));

            when(index.get("key1", "value1")).thenReturn(getHits);
            Node createdNode = mock(typeof(Node));

            when(graphdb.CreateNode()).thenReturn(createdNode);
            Node concurrentNode = mock(typeof(Node));

            when(index.PutIfAbsent(createdNode, "key1", "value1")).thenReturn(concurrentNode);
            UniqueFactory.UniqueNodeFactory unique = new UniqueNodeFactoryAnonymousInnerClass(this, index);

            // when
            UniqueEntity <Node> node = unique.GetOrCreateWithOutcome("key1", "value1");

            // then
            assertSame(node.Entity(), concurrentNode);
            assertFalse(node.WasCreated());
            verify(index).get("key1", "value1");
            verify(index).putIfAbsent(createdNode, "key1", "value1");
            verify(graphdb, times(1)).createNode();
            verify(tx).success();
        }
示例#18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void failToCreatePointOnOldDatabase()
        internal virtual void FailToCreatePointOnOldDatabase()
        {
            File storeDir = _testDirectory.storeDir();
            GraphDatabaseService        nonUpgradedStore = startNonUpgradableDatabaseWithFormat(storeDir, StandardV3_2.NAME);
            TransactionFailureException exception        = assertThrows(typeof(TransactionFailureException), () =>
            {
                using (Transaction transaction = nonUpgradedStore.BeginTx())
                {
                    Node node = nonUpgradedStore.CreateNode();
                    node.setProperty("a", pointValue(Cartesian, 1.0, 2.0));
                    transaction.success();
                }
            });

            assertEquals("Current record format does not support POINT_PROPERTIES. Please upgrade your store to the format that support requested capability.", Exceptions.rootCause(exception).Message);
            nonUpgradedStore.Shutdown();

            GraphDatabaseService restartedOldFormatDatabase = startNonUpgradableDatabaseWithFormat(storeDir, StandardV3_2.NAME);

            using (Transaction transaction = restartedOldFormatDatabase.BeginTx())
            {
                Node node = restartedOldFormatDatabase.CreateNode();
                node.SetProperty("c", "d");
                transaction.success();
            }
            restartedOldFormatDatabase.Shutdown();
        }
示例#19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void getNodesWithLabelsWithTxAddsAndRemoves()
        public virtual void getNodesWithLabelsWithTxAddsAndRemoves()
        {
            // GIVEN
            GraphDatabaseService beansAPI = DbRule.GraphDatabaseAPI;
            Node node1 = CreateNode(beansAPI, Labels.MyLabel, Labels.MyOtherLabel);
            Node node2 = CreateNode(beansAPI, Labels.MyLabel, Labels.MyOtherLabel);

            // WHEN
            Node        node3;
            ISet <Node> nodesWithMyLabel;
            ISet <Node> nodesWithMyOtherLabel;

            using (Transaction tx = beansAPI.BeginTx())
            {
                node3 = beansAPI.CreateNode(Labels.MyLabel);
                node2.RemoveLabel(Labels.MyLabel);
                // extracted here to be asserted below
                nodesWithMyLabel      = asSet(beansAPI.FindNodes(Labels.MyLabel));
                nodesWithMyOtherLabel = asSet(beansAPI.FindNodes(Labels.MyOtherLabel));
                tx.Success();
            }

            // THEN
            assertEquals(asSet(node1, node3), nodesWithMyLabel);
            assertEquals(asSet(node1, node2), nodesWithMyOtherLabel);
        }
示例#20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void given4instanceClusterWhenMasterGoesDownThenElectNewMaster() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Given4instanceClusterWhenMasterGoesDownThenElectNewMaster()
        {
            ClusterManager clusterManager = (new ClusterManager.Builder(TestDirectory.directory(TestName.MethodName))).withCluster(ClusterManager.clusterOfSize(4)).build();

            try
            {
                clusterManager.Start();
                ClusterManager.ManagedCluster cluster = clusterManager.Cluster;
                cluster.Await(allSeesAllAsAvailable());

                Logging.Logger.info("STOPPING MASTER");
                cluster.Shutdown(cluster.Master);
                Logging.Logger.info("STOPPED MASTER");

                cluster.Await(ClusterManager.masterAvailable());

                GraphDatabaseService master = cluster.Master;
                Logging.Logger.info("CREATE NODE");
                using (Transaction tx = master.BeginTx())
                {
                    master.CreateNode();
                    Logging.Logger.info("CREATED NODE");
                    tx.Success();
                }

                Logging.Logger.info("STOPPING CLUSTER");
            }
            finally
            {
                clusterManager.SafeShutdown();
            }
        }
示例#21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void createPointPropertyOnLatestDatabase()
        internal virtual void CreatePointPropertyOnLatestDatabase()
        {
            File       storeDir    = _testDirectory.storeDir();
            Label      pointNode   = Label.label("PointNode");
            string     propertyKey = "a";
            PointValue pointValue  = pointValue(Cartesian, 1.0, 2.0);

            GraphDatabaseService database = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode(pointNode);
                node.SetProperty(propertyKey, pointValue);
                transaction.Success();
            }
            database.Shutdown();

            GraphDatabaseService restartedDatabase = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction ignored = restartedDatabase.BeginTx())
            {
                assertNotNull(restartedDatabase.FindNode(pointNode, propertyKey, pointValue));
            }
            restartedDatabase.Shutdown();
        }
示例#22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void createPointArrayPropertyOnLatestDatabase()
        internal virtual void CreatePointArrayPropertyOnLatestDatabase()
        {
            File       storeDir    = _testDirectory.storeDir();
            Label      pointNode   = Label.label("PointNode");
            string     propertyKey = "a";
            PointValue pointValue  = pointValue(Cartesian, 1.0, 2.0);

            GraphDatabaseService database = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction transaction = database.BeginTx())
            {
                Node node = database.CreateNode(pointNode);
                node.SetProperty(propertyKey, new PointValue[] { pointValue, pointValue });
                transaction.Success();
            }
            database.Shutdown();

            GraphDatabaseService restartedDatabase = startDatabaseWithFormat(storeDir, Standard.LATEST_NAME);

            using (Transaction ignored = restartedDatabase.BeginTx())
            {
                using (ResourceIterator <Node> nodes = restartedDatabase.FindNodes(pointNode))
                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    Node         node   = nodes.next();
                    PointValue[] points = ( PointValue[] )node.GetProperty(propertyKey);
                    assertThat(points, arrayWithSize(2));
                }
            }
            restartedDatabase.Shutdown();
        }
示例#23
0
 private IList <IndexDefinition> Indexes(GraphDatabaseService database)
 {
     using (Transaction ignored = database.BeginTx())
     {
         return(Iterables.asList(database.Schema().Indexes));
     }
 }
示例#24
0
 private IList <ConstraintDefinition> Constraints(GraphDatabaseService database)
 {
     using (Transaction ignored = database.BeginTx())
     {
         return(Iterables.asList(database.Schema().Constraints));
     }
 }
示例#25
0
 private static void CreateNode(GraphDatabaseService database)
 {
     using (Transaction transaction = database.BeginTx())
     {
         database.CreateNode();
         transaction.Success();
     }
 }
示例#26
0
 private static void CreateSomeData(GraphDatabaseService oldMaster)
 {
     using (Transaction tx = oldMaster.BeginTx())
     {
         oldMaster.CreateNode();
         tx.Success();
     }
 }
示例#27
0
 private static void CreateNode(GraphDatabaseService database, string propertyName, Label testLabel)
 {
     using (Transaction transaction = database.BeginTx())
     {
         Node node = database.CreateNode(testLabel);
         node.SetProperty(propertyName, "value");
         transaction.Success();
     }
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testLowGrabSize()
        public virtual void TestLowGrabSize()
        {
            IDictionary <string, string> config = new Dictionary <string, string>();

            config["relationship_grab_size"] = "1";
            GraphDatabaseService graphDb = GetImpermanentDatabase(config);

            Node node1;
            Node node2;

            using (Transaction tx = graphDb.BeginTx())
            {
                node1 = graphDb.CreateNode();
                node2 = graphDb.CreateNode();
                node1.CreateRelationshipTo(node2, MyRelTypes.TEST);
                node2.CreateRelationshipTo(node1, MyRelTypes.TEST2);
                node1.CreateRelationshipTo(node2, MyRelTypes.TEST_TRAVERSAL);
                tx.Success();
            }

            using (Transaction tx = graphDb.BeginTx())
            {
                RelationshipType[] types = new RelationshipType[] { MyRelTypes.TEST, MyRelTypes.TEST2, MyRelTypes.TEST_TRAVERSAL };

                assertEquals(3, Iterables.count(node1.GetRelationships(types)));

                assertEquals(3, Iterables.count(node1.Relationships));

                assertEquals(3, Iterables.count(node2.GetRelationships(types)));

                assertEquals(3, Iterables.count(node2.Relationships));

                assertEquals(2, Iterables.count(node1.GetRelationships(OUTGOING)));

                assertEquals(1, Iterables.count(node1.GetRelationships(INCOMING)));

                assertEquals(1, Iterables.count(node2.GetRelationships(OUTGOING)));

                assertEquals(2, Iterables.count(node2.GetRelationships(INCOMING)));

                tx.Success();
            }
            graphDb.Shutdown();
        }
        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();
            }
        }
示例#30
0
 protected internal override void generateInitialData(GraphDatabaseService graphDb)
 {
     using (Transaction tx = graphDb.BeginTx())
     {
         Node node1 = set(graphDb.CreateNode());
         Node node2 = set(graphDb.CreateNode(), property("key", "exampleValue"));
         node1.CreateRelationshipTo(node2, RelationshipType.withName("C"));
         tx.Success();
     }
 }