Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void relationshipIdReusableOnlyAfterTransactionFinish()
        public virtual void RelationshipIdReusableOnlyAfterTransactionFinish()
        {
            Label testLabel      = Label.label("testLabel");
            long  relationshipId = CreateRelationship(testLabel);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.IdController idMaintenanceController = getIdMaintenanceController();
            IdController idMaintenanceController = IdMaintenanceController;

            using (Transaction transaction = DbRule.beginTx(), ResourceIterator <Node> nodes = DbRule.findNodes(testLabel))
            {
                IList <Node> nodeList = Iterators.asList(nodes);
                foreach (Node node in nodeList)
                {
                    IEnumerable <Relationship> relationships = node.GetRelationships(TestRelationshipType.Marker);
                    foreach (Relationship relationship in relationships)
                    {
                        relationship.Delete();
                    }
                }

                idMaintenanceController.Maintenance();

                Node node1 = DbRule.createNode(testLabel);
                Node node2 = DbRule.createNode(testLabel);

                Relationship relationshipTo = node1.CreateRelationshipTo(node2, TestRelationshipType.Marker);

                assertNotEquals("Relationships should have different ids.", relationshipId, relationshipTo.Id);
                transaction.Success();
            }
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void writeTransactionsAndRotateTwice() throws java.io.IOException
        private void WriteTransactionsAndRotateTwice()
        {
            LogRotation logRotation = Db.DependencyResolver.resolveDependency(typeof(LogRotation));

            // Apparently we always keep an extra log file what even though the threshold is reached... produce two then
            using (Transaction tx = Db.beginTx())
            {
                Db.createNode();
                tx.Success();
            }
            logRotation.RotateLogFile();
            using (Transaction tx = Db.beginTx())
            {
                Db.createNode();
                tx.Success();
            }
            logRotation.RotateLogFile();
            using (Transaction tx = Db.beginTx())
            {
                Db.createNode();
                tx.Success();
            }
            using (Transaction tx = Db.beginTx())
            {
                Db.createNode();
                tx.Success();
            }
        }
Exemplo n.º 3
0
        /*
         * Tests for a particular bug with dense nodes. It used to be that if a dense node had relationships
         * for only one direction, if a request for relationships of the other direction was made, no relationships
         * would be returned, ever.
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void givenDenseNodeWhenAskForWrongDirectionThenIncorrectNrOfRelsReturned()
        public virtual void GivenDenseNodeWhenAskForWrongDirectionThenIncorrectNrOfRelsReturned()
        {
            // Given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int denseNodeThreshold = int.Parse(org.neo4j.graphdb.factory.GraphDatabaseSettings.dense_node_threshold.getDefaultValue()) + 1;
            int denseNodeThreshold = int.Parse(GraphDatabaseSettings.dense_node_threshold.DefaultValue) + 1;

            Node node1;

            using (Transaction tx = Db.beginTx())
            {
                node1 = Db.createNode();
                Node node2 = Db.createNode();

                for (int i = 0; i < denseNodeThreshold; i++)
                {
                    node1.CreateRelationshipTo(node2, RelationshipType.withName("FOO"));
                }
                tx.Success();
            }

            // When/Then
            using (Transaction ignored = Db.beginTx())
            {
                Node node1b = Db.getNodeById(node1.Id);

                IEnumerable <Relationship> rels = node1b.GetRelationships(Direction.INCOMING);
                assertEquals(0, Iterables.count(rels));

                IEnumerable <Relationship> rels2 = node1b.GetRelationships(Direction.OUTGOING);
                assertEquals(denseNodeThreshold, Iterables.count(rels2));
            }
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldApplyChangesWithIntermediateConstraintViolations() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldApplyChangesWithIntermediateConstraintViolations()
        {
            // given
            using (Transaction tx = Db.beginTx())
            {
                Db.schema().constraintFor(_foo).assertPropertyIsUnique(BAR).create();
                tx.Success();
            }
            Node fourtyTwo;
            Node fourtyOne;

            using (Transaction tx = Db.beginTx())
            {
                fourtyTwo = Db.createNode(_foo);
                fourtyTwo.SetProperty(BAR, Value1);
                fourtyOne = Db.createNode(_foo);
                fourtyOne.SetProperty(BAR, Value2);
                tx.Success();
            }

            // when
            using (Transaction tx = Db.beginTx())
            {
                fourtyOne.Delete();
                fourtyTwo.SetProperty(BAR, Value2);
                tx.Success();
            }

            // then
            using (Transaction tx = Db.beginTx())
            {
                assertEquals(Value2, fourtyTwo.GetProperty(BAR));
                try
                {
                    fourtyOne.GetProperty(BAR);
                    fail("Should be deleted");
                }
                catch (NotFoundException)
                {
                    // good
                }
                tx.Success();

                assertEquals(fourtyTwo, Db.findNode(_foo, BAR, Value2));
                assertNull(Db.findNode(_foo, BAR, Value1));
            }
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 30_000) public void terminateExpiredTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TerminateExpiredTransaction()
        {
            using (Transaction transaction = Database.beginTx())
            {
                Database.createNode();
                transaction.Success();
            }

            ExpectedException.expectMessage("The transaction has been terminated.");

            using (Transaction transaction = Database.beginTx())
            {
                Node nodeById = Database.getNodeById(NODE_ID);
                nodeById.SetProperty("a", "b");
                _executor.submit(StartAnotherTransaction()).get();
            }
        }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @BeforeClass public static void given()
        public static void Given()
        {
            // database with an index on `(:Node).prop`
            using (Transaction tx = Db.beginTx())
            {
                Db.schema().indexFor(label("Node")).on("prop").create();
                tx.Success();
            }
            using (Transaction tx = Db.beginTx())
            {
                Db.schema().awaitIndexesOnline(10, SECONDS);
                tx.Success();
            }
        }
Exemplo n.º 7
0
 internal virtual void SetNodeProp(long nodeId, string propertyKey, string value)
 {
     using (Transaction tx = Db.beginTx())
     {
         Node node = Db.getNodeById(nodeId);
         node.SetProperty(propertyKey, value);
         tx.Success();
     }
 }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldListAllProperties()
        public virtual void ShouldListAllProperties()
        {
            // Given
            IDictionary <string, object> properties = new Dictionary <string, object>();

            properties["boolean"]      = true;
            properties["short_string"] = "abc";
            properties["string"]       = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW" + "XYZabcdefghijklmnopqrstuvwxyz";
            properties["long"]         = long.MaxValue;
            properties["short_array"]  = new long[] { 1, 2, 3, 4 };
            properties["array"]        = new long[] { long.MaxValue - 1, long.MaxValue - 2, long.MaxValue - 3, long.MaxValue - 4, long.MaxValue - 5, long.MaxValue - 6, long.MaxValue - 7, long.MaxValue - 8, long.MaxValue - 9, long.MaxValue - 10, long.MaxValue - 11 };

            long containerId;

            using (Transaction tx = Db.beginTx())
            {
                containerId = CreatePropertyContainer();
                PropertyContainer container = LookupPropertyContainer(containerId);

                foreach (KeyValuePair <string, object> entry in properties.SetOfKeyValuePairs())
                {
                    container.SetProperty(entry.Key, entry.Value);
                }

                tx.Success();
            }

            // When
            IDictionary <string, object> listedProperties;

            using (Transaction tx = Db.beginTx())
            {
                listedProperties = LookupPropertyContainer(containerId).AllProperties;
                tx.Success();
            }

            // Then
            assertEquals(properties.Count, listedProperties.Count);
            foreach (string key in properties.Keys)
            {
                assertObjectOrArrayEquals(properties[key], listedProperties[key]);
            }
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailToCreateConstraintIfSomeNodeLacksTheMandatoryProperty()
            public virtual void ShouldFailToCreateConstraintIfSomeNodeLacksTheMandatoryProperty()
            {
                // given
                using (Transaction tx = Db.beginTx())
                {
                    CreateOffender(Db, KEY);
                    tx.Success();
                }

                // when
                try
                {
                    using (Transaction tx = Db.beginTx())
                    {
                        CreateConstraint(Db, KEY, PROPERTY);
                        tx.Success();
                    }
                    fail("expected exception");
                }
                // then
                catch (QueryExecutionException e)
                {
                    assertThat(e.InnerException.Message, startsWith("Unable to create CONSTRAINT"));
                }
            }
Exemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void failedIndexShouldRepairAutomatically() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void FailedIndexShouldRepairAutomatically()
        {
            // given
            using (Transaction tx = Db.beginTx())
            {
                Db.schema().indexFor(_person).on("name").create();
                tx.Success();
            }
            AwaitIndexesOnline(5, SECONDS);
            CreateNamed(_person, "Johan");
            // when - we restart the database in a state where the index is not operational
            Db.restartDatabase(new SabotageNativeIndex(Random.random()));
            // then - the database should still be operational
            CreateNamed(_person, "Lars");
            AwaitIndexesOnline(5, SECONDS);
            IndexStateShouldBe(equalTo(ONLINE));
            AssertFindsNamed(_person, "Lars");
        }
Exemplo n.º 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldInterpretNoSpecifiedRelationshipsAsAll()
        public virtual void ShouldInterpretNoSpecifiedRelationshipsAsAll()
        {
            // GIVEN
            Node         node     = CreateSomeData();
            PathExpander expander = RelationshipExpanderBuilder.DescribeRelationships(map());

            // WHEN
            ISet <Relationship> expanded;

            using (Transaction tx = Db.beginTx())
            {
                expanded = asSet(expander.expand(singleNodePath(node), NO_STATE));
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                // THEN
                assertEquals(asSet(node.Relationships), expanded);
                tx.Success();
            }
        }
        private Node CreateTestNode()
        {
            Node node;

            using (Transaction transaction = DbRule.beginTx())
            {
                node = DbRule.createNode(_label);
                KernelTransaction ktx = DbRule.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
                _labelId = ktx.TokenRead().nodeLabel(_label.name());
                transaction.Success();
            }
            return(node);
        }
Exemplo n.º 13
0
        private void InitialData()
        {
            Label            unusedLabel   = Label.label("unusedLabel");
            RelationshipType unusedRelType = RelationshipType.withName("unusedRelType");
            string           unusedPropKey = "unusedPropKey";

            using (Transaction tx = Db.beginTx())
            {
                Node node1 = Db.createNode(unusedLabel);
                node1.SetProperty(unusedPropKey, "value");
                Node node2 = Db.createNode(unusedLabel);
                node2.SetProperty(unusedPropKey, 1);
                node1.CreateRelationshipTo(node2, unusedRelType);
                tx.Success();
            }
        }
Exemplo n.º 14
0
 private void VerifyFoundNodes(Label label, string sizeMismatchMessage, params long[] expectedNodeIds)
 {
     using (Transaction ignored = DbRule.beginTx())
     {
         ResourceIterator <Node> nodes    = DbRule.findNodes(label);
         IList <Node>            nodeList = Iterators.asList(nodes);
         assertThat(sizeMismatchMessage, nodeList, Matchers.hasSize(expectedNodeIds.Length));
         int index = 0;
         foreach (Node node in nodeList)
         {
             assertEquals(expectedNodeIds[index++], node.Id);
         }
     }
 }
Exemplo n.º 15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldListUsedIndexes() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldListUsedIndexes()
        {
            // given
            string label    = "IndexedLabel";
            string property = "indexedProperty";

            using (Transaction tx = _db.beginTx())
            {
                _db.schema().indexFor(label(label)).on(property).create();
                tx.Success();
            }
            EnsureIndexesAreOnline();
            ShouldListUsedIndexes(label, property);
        }
Exemplo n.º 16
0
        private ThrowingFunction <CyclicBarrier, Node, Exception> MergeThen <T1>(ThrowingConsumer <T1> action) where T1 : Exception
        {
            return(barrier =>
            {
                using (Transaction tx = Db.beginTx())
                {
                    Node node = MergeNode();

                    barrier.await();

                    action.Accept(node);

                    tx.success();
                    return node;
                }
            });
        }
Exemplo n.º 17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @BeforeClass public static void initStorage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public static void InitStorage()
        {
            using (Transaction transaction = Db.beginTx())
            {
                TokenWrite tokenWrite = Transaction.tokenWrite();
                tokenWrite.PropertyKeyGetOrCreateForName(PROP1);
                tokenWrite.PropertyKeyGetOrCreateForName(PROP2);
                tokenWrite.LabelGetOrCreateForName(LABEL1);
                tokenWrite.LabelGetOrCreateForName(LABEL2);
                tokenWrite.RelationshipTypeGetOrCreateForName(TYPE1);
                transaction.Success();
            }
            SchemaStore schemaStore = ResolveDependency(typeof(RecordStorageEngine)).testAccessNeoStores().SchemaStore;

            _storage = new SchemaStorage(schemaStore);
        }
Exemplo n.º 18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleSizesCloseToTheLimit()
        public virtual void ShouldHandleSizesCloseToTheLimit()
        {
            // given
            CreateIndex(KEY);

            // when
            IDictionary <string, long> strings = new Dictionary <string, long>();

            using (Transaction tx = Db.beginTx())
            {
                for (int i = 0; i < 1_000; i++)
                {
                    string @string;
                    do
                    {
                        @string = Random.nextAlphaNumericString(3_000, 4_000);
                    } while (strings.ContainsKey(@string));

                    Node node = Db.createNode(LABEL);
                    node.SetProperty(KEY, @string);
                    strings[@string] = node.Id;
                }
                tx.Success();
            }

            // then
            using (Transaction tx = Db.beginTx())
            {
                foreach (string @string in strings.Keys)
                {
                    Node node = Db.findNode(LABEL, KEY, @string);
                    assertEquals(strings[@string], node.Id);
                }
                tx.Success();
            }
        }
Exemplo n.º 19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 15000) public void commitDuringContinuousCheckpointing() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CommitDuringContinuousCheckpointing()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.index.Index<org.neo4j.graphdb.Node> index;
            Index <Node> index;

            using (Transaction tx = Db.beginTx())
            {
                index = Db.index().forNodes(INDEX_NAME, stringMap(Org.Neo4j.Graphdb.index.IndexManager_Fields.PROVIDER, DummyIndexExtensionFactory.IDENTIFIER));
                tx.Success();
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean done = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean         done    = new AtomicBoolean();
            Workers <ThreadStart> workers = new Workers <ThreadStart>(this.GetType().Name);

            for (int i = 0; i < TOTAL_ACTIVE_THREADS; i++)
            {
                workers.Start(new RunnableAnonymousInnerClass(this, index, tx, done));
            }

            Thread.Sleep(SECONDS.toMillis(2));
            done.set(true);
            workers.AwaitAndThrowOnError();

            NeoStores neoStores = GetDependency(typeof(RecordStorageEngine)).testAccessNeoStores();

            assertThat("Count store should be rotated once at least", neoStores.Counts.txId(), greaterThan(0L));

            long lastRotationTx          = GetDependency(typeof(CheckPointer)).forceCheckPoint(new SimpleTriggerInfo("test"));
            TransactionIdStore txIdStore = GetDependency(typeof(TransactionIdStore));

            assertEquals("NeoStore last closed transaction id should be equal last count store rotation transaction id.", txIdStore.LastClosedTransactionId, lastRotationTx);
            assertEquals("Last closed transaction should be last rotated tx in count store", txIdStore.LastClosedTransactionId, neoStores.Counts.txId());
        }
Exemplo n.º 20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldChaseTheLivingRelationships() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldChaseTheLivingRelationships()
        {
            // GIVEN a sound relationship chain
            int  numberOfRelationships = THRESHOLD / 2;
            Node node;

            using (Transaction tx = Db.beginTx())
            {
                node = Db.createNode();
                for (int i = 0; i < numberOfRelationships; i++)
                {
                    node.CreateRelationshipTo(Db.createNode(), TEST);
                }
                tx.Success();
            }
            Relationship[] relationships;
            using (Transaction tx = Db.beginTx())
            {
                relationships = asArray(typeof(Relationship), node.Relationships);
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                // WHEN getting the relationship iterator, i.e. starting to traverse this relationship chain,
                // the cursor eagerly goes to the first relationship before we call #hasNexxt/#next.
                IEnumerator <Relationship> iterator = node.Relationships.GetEnumerator();

                // Therefore we delete relationships [1] and [2] (the second and third), since currently
                // the relationship iterator has read [0] and have already decided to go to [1] after our next
                // call to #next
                DeleteRelationshipsInSeparateThread(relationships[1], relationships[2]);

                // THEN the relationship iterator should recognize the unused relationship, but still try to find
                // the next used relationship in this chain by following the pointers in the unused records.
                AssertNext(relationships[0], iterator);
                AssertNext(relationships[3], iterator);
                AssertNext(relationships[4], iterator);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(iterator.hasNext());
                tx.Success();
            }
        }
Exemplo n.º 21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void prepDB()
        public virtual void PrepDB()
        {
            using (Transaction transaction = Db.beginTx())
            {
                _node1 = Db.createNode(label("hej"), label("ha"), label("he"));
                _node1.setProperty("hej", "value");
                _node1.setProperty("ha", "value1");
                _node1.setProperty("he", "value2");
                _node1.setProperty("ho", "value3");
                _node1.setProperty("hi", "value4");
                _node2 = Db.createNode();
                Relationship rel = _node1.createRelationshipTo(_node2, RelationshipType.withName("hej"));
                rel.SetProperty("hej", "valuuu");
                rel.SetProperty("ha", "value1");
                rel.SetProperty("he", "value2");
                rel.SetProperty("ho", "value3");
                rel.SetProperty("hi", "value4");

                transaction.Success();
            }
        }
Exemplo n.º 22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDropUniquenessConstraintWithBackingIndexNotInUse()
		 public virtual void ShouldDropUniquenessConstraintWithBackingIndexNotInUse()
		 {
			  // given
			  using ( Transaction tx = Db.beginTx() )
			  {
					Db.schema().constraintFor(_label).assertPropertyIsUnique(_key).create();
					tx.Success();
			  }

			  // when intentionally breaking the schema by setting the backing index rule to unused
			  RecordStorageEngine storageEngine = Db.DependencyResolver.resolveDependency( typeof( RecordStorageEngine ) );
			  SchemaStore schemaStore = storageEngine.TestAccessNeoStores().SchemaStore;
			  SchemaRule indexRule = single( filter( rule => rule is StoreIndexDescriptor, schemaStore.LoadAllSchemaRules() ) );
			  SetSchemaRecordNotInUse( schemaStore, indexRule.Id );
			  // At this point the SchemaCache doesn't know about this change so we have to reload it
			  storageEngine.LoadSchemaCache();
			  using ( Transaction tx = Db.beginTx() )
			  {
					single( Db.schema().getConstraints(_label).GetEnumerator() ).drop();
					tx.Success();
			  }

			  // then
			  using ( Transaction ignore = Db.beginTx() )
			  {
					assertFalse( Db.schema().Constraints.GetEnumerator().hasNext() );
					assertFalse( Db.schema().Indexes.GetEnumerator().hasNext() );
			  }
		 }
Exemplo n.º 23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void createTokens()
        public virtual void CreateTokens()
        {
            using (Transaction tx = Db.beginTx())
            {
                for (int i = 0; i < _threads; i++)
                {
                    Db.createNode(Label(i)).setProperty(KEY, i);
                }
                tx.Success();
            }
        }