Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void setManyGraphProperties()
        public virtual void SetManyGraphProperties()
        {
            GraphDatabaseAPI db = ( GraphDatabaseAPI )_factory.newImpermanentDatabase();

            Transaction tx = Db.beginTx();

            object[] values = new object[] { 10, "A string value", new float[] { 1234.567F, 7654.321F }, "A rather longer string which wouldn't fit inlined #!)(&¤" };
            int      count  = 200;

            for (int i = 0; i < count; i++)
            {
                Properties(db).setProperty("key" + i, values[i % values.Length]);
            }
            tx.Success();
            tx.Close();

            for (int i = 0; i < count; i++)
            {
                assertThat(Properties(db), inTx(db, hasProperty("key" + i).withValue(values[i % values.Length])));
            }
            for (int i = 0; i < count; i++)
            {
                assertThat(Properties(db), inTx(db, hasProperty("key" + i).withValue(values[i % values.Length])));
            }
            Db.shutdown();
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void firstRecordOtherThanZeroIfNotFirst()
        public virtual void FirstRecordOtherThanZeroIfNotFirst()
        {
            File             storeDir = TestDirectory.databaseDir();
            GraphDatabaseAPI db       = ( GraphDatabaseAPI )_factory.newImpermanentDatabase(storeDir);
            Transaction      tx       = Db.beginTx();
            Node             node     = Db.createNode();

            node.SetProperty("name", "Yo");
            tx.Success();
            tx.Close();
            Db.shutdown();

            db = ( GraphDatabaseAPI )_factory.newImpermanentDatabase(storeDir);
            tx = Db.beginTx();
            Properties(db).setProperty("test", "something");
            tx.Success();
            tx.Close();
            Db.shutdown();

            Config       config       = Config.defaults();
            StoreFactory storeFactory = new StoreFactory(TestDirectory.databaseLayout(), config, new DefaultIdGeneratorFactory(Fs.get()), PageCacheRule.getPageCache(Fs.get()), Fs.get(), NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY);
            NeoStores    neoStores    = storeFactory.OpenAllNeoStores();
            long         prop         = neoStores.MetaDataStore.GraphNextProp;

            assertTrue(prop != 0);
            neoStores.Close();
        }
Ejemplo n.º 3
0
 private void LoadNode(GraphDatabaseAPI db, Node node)
 {
     using (Transaction ignored = Db.beginTx())
     {
         Iterables.count(node.Relationships);
     }
 }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateACountsStoreWhenThereAreUnusedNodeRecordsInTheDB()
        public virtual void ShouldCreateACountsStoreWhenThereAreUnusedNodeRecordsInTheDB()
        {
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("deprecation") final org.neo4j.kernel.internal.GraphDatabaseAPI db = (org.neo4j.kernel.internal.GraphDatabaseAPI) dbBuilder.newGraphDatabase();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            GraphDatabaseAPI db = ( GraphDatabaseAPI )_dbBuilder.newGraphDatabase();

            using (Transaction tx = Db.beginTx())
            {
                Db.createNode(Label.label("A"));
                Db.createNode(Label.label("C"));
                Node node = Db.createNode(Label.label("D"));
                Db.createNode();
                node.Delete();
                tx.Success();
            }
            long lastCommittedTransactionId = GetLastTxId(db);

            Db.shutdown();

            RebuildCounts(lastCommittedTransactionId);

            using (Lifespan life = new Lifespan())
            {
                CountsTracker store = life.Add(CreateCountsTracker());
                assertEquals(BASE_TX_ID + 1 + 1 + 1 + 1, store.TxId());
                assertEquals(3, store.TotalEntriesStored());
                assertEquals(3, Get(store, nodeKey(-1)));
                assertEquals(1, Get(store, nodeKey(0)));
                assertEquals(1, Get(store, nodeKey(1)));
                assertEquals(0, Get(store, nodeKey(2)));
                assertEquals(0, Get(store, nodeKey(3)));
            }
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private int figureOutSampleTransactionSizeBytes() throws java.io.IOException
        private int FigureOutSampleTransactionSizeBytes()
        {
            _db = NewDb("true", 5);
            DoTransaction();
            _db.shutdown();
            return(( int )_fs.getFileSize(_files.getLogFileForVersion(0)));
        }
Ejemplo n.º 6
0
        private void ShiftHighId(GraphDatabaseAPI db)
        {
            RecordStorageEngine storageEngine = Db.DependencyResolver.resolveDependency(typeof(RecordStorageEngine));
            NeoStores           neoStores     = storageEngine.TestAccessNeoStores();

            neoStores.RelationshipTypeTokenStore.HighId = short.MaxValue - RELATIONSHIP_COUNT / 2;
        }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private int createSimpleDatabase(final org.neo4j.kernel.internal.GraphDatabaseAPI graph)
        private int CreateSimpleDatabase(GraphDatabaseAPI graph)
        {
            const int numberOfNodes = 10;

            (new Transactor(graph, () =>
            {
                for (int i = 0; i < numberOfNodes; i++)
                {
                    graph.CreateNode();
                }

                foreach (Node n1 in graph.AllNodes)
                {
                    foreach (Node n2 in graph.AllNodes)
                    {
                        if (n1.Equals(n2))
                        {
                            continue;
                        }

                        n1.createRelationshipTo(n2, RelationshipType.withName("REL"));
                    }
                }
            })).execute();

            return(numberOfNodes);
        }
Ejemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void uniqueIndexSeekDoNotLeakIndexReaders() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void UniqueIndexSeekDoNotLeakIndexReaders()
        {
            TrackingIndexExtensionFactory indexExtensionFactory = new TrackingIndexExtensionFactory();
            GraphDatabaseAPI database = CreateDatabase(indexExtensionFactory);

            try
            {
                Label  label        = label("spaceship");
                string nameProperty = "name";
                CreateUniqueConstraint(database, label, nameProperty);

                GenerateRandomData(database, label, nameProperty);

                assertNotNull(indexExtensionFactory.IndexProvider);
                assertThat(numberOfClosedReaders(), greaterThan(0L));
                assertThat(numberOfOpenReaders(), greaterThan(0L));
                assertThat(numberOfClosedReaders(), CloseTo(numberOfOpenReaders(), 1));

                LockNodeUsingUniqueIndexSeek(database, label, nameProperty);

                assertThat(numberOfClosedReaders(), CloseTo(numberOfOpenReaders(), 1));
            }
            finally
            {
                database.Shutdown();
            }
        }
Ejemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void basicProperties()
        public virtual void BasicProperties()
        {
            GraphDatabaseAPI  db = ( GraphDatabaseAPI )_factory.newImpermanentDatabase();
            PropertyContainer graphProperties = Properties(db);

            assertThat(graphProperties, inTx(db, not(hasProperty("test"))));

            Transaction tx = Db.beginTx();

            graphProperties.SetProperty("test", "yo");
            assertEquals("yo", graphProperties.GetProperty("test"));
            tx.Success();
            tx.Close();
            assertThat(graphProperties, inTx(db, hasProperty("test").withValue("yo")));
            tx = Db.beginTx();
            assertNull(graphProperties.RemoveProperty("something non existent"));
            assertEquals("yo", graphProperties.RemoveProperty("test"));
            assertNull(graphProperties.GetProperty("test", null));
            graphProperties.SetProperty("other", 10);
            assertEquals(10, graphProperties.GetProperty("other"));
            graphProperties.SetProperty("new", "third");
            tx.Success();
            tx.Close();
            assertThat(graphProperties, inTx(db, not(hasProperty("test"))));
            assertThat(graphProperties, inTx(db, hasProperty("other").withValue(10)));
            assertThat(getPropertyKeys(db, graphProperties), containsOnly("other", "new"));

            tx = Db.beginTx();
            graphProperties.SetProperty("rollback", true);
            assertEquals(true, graphProperties.GetProperty("rollback"));
            tx.Close();
            assertThat(graphProperties, inTx(db, not(hasProperty("rollback"))));
            Db.shutdown();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Check that lifecycle status of extension is SHUTDOWN
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeShutdown()
        public void ShouldBeShutdown()
        {
            GraphDatabaseAPI graphdb = GraphDb(0);

            graphdb.Shutdown();

            assertEquals(LifecycleStatus.SHUTDOWN, graphdb.DependencyResolver.resolveDependency(typeof(GlobalKernelExtensions)).resolveDependency(typeof(DummyExtension)).Status);
        }
Ejemplo n.º 11
0
        public static HostnamePort GetConnectorAddress(GraphDatabaseAPI db, string connectorKey)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.configuration.ConnectorPortRegister portRegister = db.getDependencyResolver().resolveDependency(org.neo4j.kernel.configuration.ConnectorPortRegister.class);
            ConnectorPortRegister portRegister = Db.DependencyResolver.resolveDependency(typeof(ConnectorPortRegister));

            return(requireNonNull(portRegister.GetLocalAddress(connectorKey), "Connector not found: " + connectorKey));
        }
Ejemplo n.º 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUseForsetiAsDefaultLockManager()
        public virtual void ShouldUseForsetiAsDefaultLockManager()
        {
            // When
            GraphDatabaseAPI db = DbRule.GraphDatabaseAPI;

            // Then
            assertThat(Db.DependencyResolver.resolveDependency(typeof(Locks)), instanceOf(typeof(ForsetiLockManager)));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDetectSabotagedRelationshipWhereEverItIs() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDetectSabotagedRelationshipWhereEverItIs()
        {
            // GIVEN a database which lots of relationships
            GraphDatabaseAPI db = GraphDatabaseAPI;
            Sabotage         sabotage;

            try
            {
                Node[]         nodes         = new Node[1_000];
Ejemplo n.º 14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void createCompositeIndex(org.neo4j.graphdb.GraphDatabaseService graphDb, String label, String... properties) throws Exception
        protected internal override void CreateCompositeIndex(GraphDatabaseService graphDb, string label, params string[] properties)
        {
            GraphDatabaseAPI  @internal   = ( GraphDatabaseAPI )graphDb;
            KernelTransaction ktx         = @internal.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
            SchemaWrite       schemaWrite = ktx.SchemaWrite();
            TokenWrite        token       = ktx.TokenWrite();

            schemaWrite.IndexCreate(SchemaDescriptorFactory.forLabel(token.LabelGetOrCreateForName("Person"), token.PropertyKeyGetOrCreateForName("firstname"), token.PropertyKeyGetOrCreateForName("surname")));
        }
Ejemplo n.º 15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowUsingCommunityLockManager()
        public virtual void ShouldAllowUsingCommunityLockManager()
        {
            // When
            DbRule.withSetting(GraphDatabaseSettings.lock_manager, "community");
            GraphDatabaseAPI db = DbRule.GraphDatabaseAPI;

            // Then
            assertThat(Db.DependencyResolver.resolveDependency(typeof(Locks)), instanceOf(typeof(CommunityLockManger)));
        }
Ejemplo n.º 16
0
 private Index <Node> CreateNodeIndex(GraphDatabaseAPI db)
 {
     using (Transaction tx = Db.beginTx())
     {
         Index <Node> index = Db.index().forNodes("test", stringMap(PROVIDER, IDENTIFIER));
         tx.Success();
         return(index);
     }
 }
Ejemplo n.º 17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void canRemoveFilesAndReinvokeShutdown() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CanRemoveFilesAndReinvokeShutdown()
        {
            GraphDatabaseAPI      databaseAPI           = ( GraphDatabaseAPI )this._graphDb;
            FileSystemAbstraction fileSystemAbstraction = GetDatabaseFileSystem(databaseAPI);

            _graphDb.shutdown();
            fileSystemAbstraction.DeleteRecursively(databaseAPI.DatabaseLayout().databaseDirectory());
            _graphDb.shutdown();
        }
Ejemplo n.º 18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: Object get(org.neo4j.kernel.internal.GraphDatabaseAPI graphDb, ParameterList parameters, String name) throws org.neo4j.server.rest.repr.BadInputException
        internal override object Get(GraphDatabaseAPI graphDb, ParameterList parameters, string name)
        {
            string typeName = parameters.GetString(name);

            if (string.ReferenceEquals(typeName, null))
            {
                return(null);
            }
            return(RelationshipType.withName(typeName));
        }
Ejemplo n.º 19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp()
        public virtual void SetUp()
        {
            GraphDatabaseAPI api = DbRule.GraphDatabaseAPI;

            _graph = api;
            DependencyResolver dependencyResolver = api.DependencyResolver;

            this._bridge = dependencyResolver.ResolveDependency(typeof(ThreadToStatementContextBridge));
            this._tx     = _graph.beginTx();
        }
Ejemplo n.º 20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testUdcHostSettingIsUnchanged()
        public virtual void TestUdcHostSettingIsUnchanged()
        {
            //noinspection deprecation
            GraphDatabaseAPI db     = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).newImpermanentDatabaseBuilder().setConfig(UdcSettings.UdcHost, TEST_HOST_AND_PORT).newGraphDatabase();
            Config           config = Db.DependencyResolver.resolveDependency(typeof(Config));

            assertEquals(TEST_HOST_AND_PORT, config.Get(UdcSettings.UdcHost).ToString());

            Db.shutdown();
        }
Ejemplo n.º 21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void getNonExistentGraphPropertyWithDefaultValue()
        public virtual void getNonExistentGraphPropertyWithDefaultValue()
        {
            GraphDatabaseAPI  db = ( GraphDatabaseAPI )_factory.newImpermanentDatabase();
            PropertyContainer graphProperties = Properties(db);
            Transaction       tx = Db.beginTx();

            assertEquals("default", graphProperties.GetProperty("test", "default"));
            tx.Success();
            tx.Close();
            Db.shutdown();
        }
Ejemplo n.º 22
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: Object get(org.neo4j.kernel.internal.GraphDatabaseAPI graphDb, ParameterList parameters, String name) throws org.neo4j.server.rest.repr.BadInputException
        internal override object Get(GraphDatabaseAPI graphDb, ParameterList parameters, string name)
        {
            try
            {
                return(parameters.GetUri(name).toURL());
            }
            catch (MalformedURLException e)
            {
                throw new BadInputException(e);
            }
        }
Ejemplo n.º 23
0
 private static void GenerateRandomData(GraphDatabaseAPI database, Label label, string nameProperty)
 {
     for (int i = 0; i < 1000; i++)
     {
         using (Transaction transaction = database.BeginTx())
         {
             Node node = database.CreateNode(label);
             node.SetProperty(nameProperty, "PlanetExpress" + i);
             transaction.Success();
         }
     }
 }
Ejemplo n.º 24
0
 private static void CreateUniqueConstraint(GraphDatabaseAPI database, Label label, string nameProperty)
 {
     using (Transaction transaction = database.BeginTx())
     {
         database.Schema().constraintFor(label).assertPropertyIsUnique(nameProperty).create();
         transaction.Success();
     }
     using (Transaction transaction = database.BeginTx())
     {
         database.Schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
         transaction.Success();
     }
 }
Ejemplo n.º 25
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void tryOnce(final org.neo4j.kernel.internal.GraphDatabaseAPI db, final org.neo4j.graphdb.Node node) throws Throwable
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        private void TryOnce(GraphDatabaseAPI db, Node node)
        {
            Race race = (new Race()).withRandomStartDelays();

            race.AddContestants(Runtime.Runtime.availableProcessors(), () =>
            {
                using (Transaction ignored = Db.beginTx())
                {
                    assertEquals(_relCount, count(node.Relationships));
                }
            });
            race.Go();
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Check that lifecycle status of extension is STARTED
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeStarted()
        public void ShouldBeStarted()
        {
            GraphDatabaseAPI graphdb = GraphDb(0);

            try
            {
                assertEquals(LifecycleStatus.STARTED, graphdb.DependencyResolver.resolveDependency(typeof(GlobalKernelExtensions)).resolveDependency(typeof(DummyExtension)).Status);
            }
            finally
            {
                graphdb.Shutdown();
            }
        }
Ejemplo n.º 27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void twoUncleanInARow() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TwoUncleanInARow()
        {
            File databaseDir = TestDirectory.databaseDir();

            using (EphemeralFileSystemAbstraction snapshot = ProduceUncleanStore(Fs.get(), databaseDir))
            {
                using (EphemeralFileSystemAbstraction snapshot2 = ProduceUncleanStore(snapshot, databaseDir))
                {
                    GraphDatabaseAPI db = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).setFileSystem(ProduceUncleanStore(snapshot2, databaseDir)).newImpermanentDatabase(databaseDir);
                    assertThat(Properties(db), inTx(db, hasProperty("prop").withValue("Some value")));
                    Db.shutdown();
                }
            }
        }
Ejemplo n.º 28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateAnEmptyCountsStoreFromAnEmptyDatabase()
        public virtual void ShouldCreateAnEmptyCountsStoreFromAnEmptyDatabase()
        {
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("deprecation") final org.neo4j.kernel.internal.GraphDatabaseAPI db = (org.neo4j.kernel.internal.GraphDatabaseAPI) dbBuilder.newGraphDatabase();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            GraphDatabaseAPI db = ( GraphDatabaseAPI )_dbBuilder.newGraphDatabase();
            long             lastCommittedTransactionId = GetLastTxId(db);

            Db.shutdown();

            RebuildCounts(lastCommittedTransactionId);

            CheckEmptyCountStore();
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Check that dependencies can be accessed
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void dependenciesCanBeRetrieved()
        public void DependenciesCanBeRetrieved()
        {
            GraphDatabaseAPI graphdb = GraphDb(0);

            try
            {
                assertEquals(graphdb.DependencyResolver.resolveDependency(typeof(Config)), graphdb.DependencyResolver.resolveDependency(typeof(GlobalKernelExtensions)).resolveDependency(typeof(DummyExtension)).Dependencies.Config);
                assertEquals(graphdb.DependencyResolver.resolveDependency(typeof(DatabaseManager)), graphdb.DependencyResolver.resolveDependency(typeof(GlobalKernelExtensions)).resolveDependency(typeof(DummyExtension)).Dependencies.DatabaseManager);
            }
            finally
            {
                graphdb.Shutdown();
            }
        }
Ejemplo n.º 30
0
        private void VerifyContent()
        {
            GraphDatabaseAPI newDb = Db.GraphDatabaseAPI;

            using (Transaction tx = newDb.BeginTx())
            {
                assertEquals(1L, Iterators.stream(newDb.Schema().getIndexes(_label).GetEnumerator()).count());
                assertNotNull(newDb.FindNode(_label, _propKey, _numberValue));
                assertNotNull(newDb.FindNode(_label, _propKey, _stringValue));
                assertNotNull(newDb.FindNode(_label, _propKey, _spatialValue));
                assertNotNull(newDb.FindNode(_label, _propKey, _temporalValue));
                tx.Success();
            }
        }