//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleSingleNodePath()
        public virtual void ShouldHandleSingleNodePath()
        {
            // Given
            Node node;

            using (Transaction tx = Db.beginTx())
            {
                node = Db.createNode();
                tx.Success();
            }

            // When
            Path mapped = _mapper.mapPath(path(AsNodeValues(node), AsRelationshipsValues()));

            // Then
            using (Transaction ignore = Db.beginTx())
            {
                assertThat(mapped.Length(), equalTo(0));
                assertThat(mapped.StartNode(), equalTo(node));
                assertThat(mapped.EndNode(), equalTo(node));
                assertThat(Iterables.asList(mapped.Relationships()), hasSize(0));
                assertThat(Iterables.asList(mapped.ReverseRelationships()), hasSize(0));
                assertThat(Iterables.asList(mapped.Nodes()), equalTo(singletonList(node)));
                assertThat(Iterables.asList(mapped.ReverseNodes()), equalTo(singletonList(node)));
                assertThat(mapped.LastRelationship(), nullValue());
                assertThat(Iterators.asList(mapped.GetEnumerator()), equalTo(singletonList(node)));
            }
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTerminateOutdatedTransactions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTerminateOutdatedTransactions()
        {
            // given
            long safeZone                       = 10;
            int  txCount                        = 3;
            long firstCommitTimestamp           = 10;
            long commitTimestampInterval        = 2;
            TransactionBatchCommitter committer = NewBatchCommitter(safeZone);

            TransactionChain  chain = CreateTxChain(txCount, firstCommitTimestamp, commitTimestampInterval);
            long              timestampOutsideSafeZone = chain.Last.transactionRepresentation().LatestCommittedTxWhenStarted - safeZone - 1;
            KernelTransaction txToTerminate            = NewKernelTransaction(timestampOutsideSafeZone);
            KernelTransaction tx = NewKernelTransaction(firstCommitTimestamp - 1);

            when(_kernelTransactions.activeTransactions()).thenReturn(Iterators.asSet(NewHandle(txToTerminate), NewHandle(tx)));

            // when
            committer.Apply(chain.First, chain.Last);

            // then
            verify(txToTerminate).markForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.Outdated);
            verify(tx, never()).markForTermination(any());
            _logProvider.formattedMessageMatcher().assertContains("Marking transaction for termination");
            _logProvider.formattedMessageMatcher().assertContains("lastCommittedTxId:" + (BASE_TX_ID + txCount - 1));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleSingleRelationshipPath()
        public virtual void ShouldHandleSingleRelationshipPath()
        {
            // Given
            Node         start, end;
            Relationship relationship;

            using (Transaction tx = Db.beginTx())
            {
                start        = Db.createNode();
                end          = Db.createNode();
                relationship = start.CreateRelationshipTo(end, RelationshipType.withName("R"));
                tx.Success();
            }

            // When
            Path mapped = _mapper.mapPath(path(AsNodeValues(start, end), AsRelationshipsValues(relationship)));

            // Then
            using (Transaction ignore = Db.beginTx())
            {
                assertThat(mapped.Length(), equalTo(1));
                assertThat(mapped.StartNode(), equalTo(start));
                assertThat(mapped.EndNode(), equalTo(end));
                assertThat(Iterables.asList(mapped.Relationships()), equalTo(singletonList(relationship)));
                assertThat(Iterables.asList(mapped.ReverseRelationships()), equalTo(singletonList(relationship)));
                assertThat(Iterables.asList(mapped.Nodes()), equalTo(Arrays.asList(start, end)));
                assertThat(Iterables.asList(mapped.ReverseNodes()), equalTo(Arrays.asList(end, start)));
                assertThat(mapped.LastRelationship(), equalTo(relationship));
                assertThat(Iterators.asList(mapped.GetEnumerator()), equalTo(Arrays.asList(start, relationship, end)));
            }
        }
Exemple #4
0
 private Path GetFirstPath(Traverser traverse)
 {
     using (ResourceIterator <Path> iterator = traverse.GetEnumerator())
     {
         return(Iterators.first(iterator));
     }
 }
Exemple #5
0
        private SchemaRead SchemaWithIndexes(params IndexReference[] indexes)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.internal.kernel.api.SchemaRead schemaRead = mock(org.neo4j.internal.kernel.api.SchemaRead.class);
            SchemaRead schemaRead = mock(typeof(SchemaRead));

            when(schemaRead.IndexesGetAll()).thenReturn(Iterators.iterator(indexes));
            return(schemaRead);
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = IllegalArgumentException.class) public void bothSidesMustHaveSameUniqueness()
        public virtual void BothSidesMustHaveSameUniqueness()
        {
            CreateGraph("A TO B");

            Traverser traverse = GraphDb.bidirectionalTraversalDescription().startSide(GraphDb.traversalDescription().uniqueness(Uniqueness.NODE_GLOBAL)).endSide(GraphDb.traversalDescription().uniqueness(Uniqueness.RELATIONSHIP_GLOBAL)).traverse(GetNodeWithName("A"), GetNodeWithName("B"));

            using (ResourceIterator <Path> iterator = traverse.GetEnumerator())
            {
                Iterators.count(iterator);
            }
        }
Exemple #7
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();
            }
        }
Exemple #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void flushStoreFilesWithCorrectCheckpointTriggerName() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void FlushStoreFilesWithCorrectCheckpointTriggerName()
        {
            CheckPointer             checkPointer = mock(typeof(CheckPointer));
            StoreCopyCheckPointMutex mutex        = new StoreCopyCheckPointMutex();

            NeoStoreDataSource dataSource = mock(typeof(NeoStoreDataSource));

            when(dataSource.StoreCopyCheckPointMutex).thenReturn(mutex);
            when(dataSource.ListStoreFiles(anyBoolean())).thenReturn(Iterators.emptyResourceIterator());

            DefaultMasterImplSPI master = new DefaultMasterImplSPI(mock(typeof(GraphDatabaseAPI), RETURNS_MOCKS), mock(typeof(FileSystemAbstraction)), new Monitors(), mockedTokenHolders(), mock(typeof(IdGeneratorFactory)), mock(typeof(TransactionCommitProcess)), checkPointer, mock(typeof(TransactionIdStore)), mock(typeof(LogicalTransactionStore)), dataSource, NullLogProvider.Instance);

            master.FlushStoresAndStreamStoreFiles(mock(typeof(StoreWriter)));

            TriggerInfo expectedTriggerInfo = new SimpleTriggerInfo(DefaultMasterImplSPI.STORE_COPY_CHECKPOINT_TRIGGER);

            verify(checkPointer).tryCheckPoint(expectedTriggerInfo);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNotTimeoutSchemaTransactions()
        internal virtual void ShouldNotTimeoutSchemaTransactions()
        {
            // given
            KernelTransactions       kernelTransactions = mock(typeof(KernelTransactions));
            FakeClock                clock   = new FakeClock(100, MINUTES);
            KernelTransactionMonitor monitor = new KernelTransactionMonitor(kernelTransactions, clock, NullLogService.Instance);
            // a 2 minutes old schema transaction which has a timeout of 1 minute
            KernelTransactionHandle oldSchemaTransaction = mock(typeof(KernelTransactionHandle));

            when(oldSchemaTransaction.SchemaTransaction).thenReturn(true);
            when(oldSchemaTransaction.StartTime()).thenReturn(clock.Millis() - MINUTES.toMillis(2));
            when(oldSchemaTransaction.TimeoutMillis()).thenReturn(MINUTES.toMillis(1));
            when(kernelTransactions.ActiveTransactions()).thenReturn(Iterators.asSet(oldSchemaTransaction));

            // when
            monitor.Run();

            // then
            verify(oldSchemaTransaction, times(1)).SchemaTransaction;
            verify(oldSchemaTransaction, never()).markForTermination(any());
        }
Exemple #10
0
        public override ResourceIterator <T> Iterator()
        {
            try
            {
                if (_cursor.next())
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final T first = cursor.get();
                    T first = _cursor.get();

                    return(new ResourceIteratorAnonymousInnerClass(this, first));
                }

                _cursor.close();
                return(Iterators.asResourceIterator(Collections.emptyIterator()));
            }
            catch (IOException)
            {
                return(Iterators.asResourceIterator(Collections.emptyIterator()));
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleLongPath()
        public virtual void ShouldHandleLongPath()
        {
            // Given
            Node         a, b, c, d, e;
            Relationship r1, r2, r3, r4;

            using (Transaction tx = Db.beginTx())
            {
                a  = Db.createNode();
                b  = Db.createNode();
                c  = Db.createNode();
                d  = Db.createNode();
                e  = Db.createNode();
                r1 = a.CreateRelationshipTo(b, RelationshipType.withName("R"));
                r2 = b.CreateRelationshipTo(c, RelationshipType.withName("R"));
                r3 = c.CreateRelationshipTo(d, RelationshipType.withName("R"));
                r4 = d.CreateRelationshipTo(e, RelationshipType.withName("R"));
                tx.Success();
            }

            // When
            Path mapped = _mapper.mapPath(path(AsNodeValues(a, b, c, d, e), AsRelationshipsValues(r1, r2, r3, r4)));

            // Then
            using (Transaction ignore = Db.beginTx())
            {
                assertThat(mapped.Length(), equalTo(4));
                assertThat(mapped.StartNode(), equalTo(a));
                assertThat(mapped.EndNode(), equalTo(e));
                assertThat(Iterables.asList(mapped.Relationships()), equalTo(Arrays.asList(r1, r2, r3, r4)));
                assertThat(Iterables.asList(mapped.ReverseRelationships()), equalTo(Arrays.asList(r4, r3, r2, r1)));
                assertThat(Iterables.asList(mapped.Nodes()), equalTo(Arrays.asList(a, b, c, d, e)));
                assertThat(Iterables.asList(mapped.ReverseNodes()), equalTo(Arrays.asList(e, d, c, b, a)));
                assertThat(mapped.LastRelationship(), equalTo(r4));
                assertThat(Iterators.asList(mapped.GetEnumerator()), equalTo(Arrays.asList(a, r1, b, r2, c, r3, d, r4, e)));
            }
        }
Exemple #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private Object[] single(org.neo4j.collection.RawIterator<Object[], org.neo4j.internal.kernel.api.exceptions.ProcedureException> result) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException
        private object[] Single(RawIterator <object[], ProcedureException> result)
        {
            return(Iterators.single(asList(result).GetEnumerator()));
        }
Exemple #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowConcurrentViolationOfConstraint() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAllowConcurrentViolationOfConstraint()
        {
            // Given
            GraphDatabaseAPI graphDb = Db.GraphDatabaseAPI;

            System.Func <KernelTransaction> ktxSupplier = () => graphDb.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);

            Label  label            = label("Foo");
            string propertyKey      = "bar";
            string conflictingValue = "baz";

            // a constraint
            using (Transaction tx = graphDb.BeginTx())
            {
                graphDb.Schema().constraintFor(label).assertPropertyIsUnique(propertyKey).create();
                tx.Success();
            }

            // When
            using (Transaction tx = graphDb.BeginTx())
            {
                KernelTransaction ktx         = ktxSupplier();
                int             labelId       = ktx.TokenRead().nodeLabel(label.Name());
                int             propertyKeyId = ktx.TokenRead().propertyKey(propertyKey);
                IndexDescriptor index         = TestIndexDescriptorFactory.uniqueForLabel(labelId, propertyKeyId);
                Read            read          = ktx.DataRead();
                using (NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor())
                {
                    read.NodeIndexSeek(ktx.SchemaRead().index(labelId, propertyKeyId), cursor, IndexOrder.NONE, false, IndexQuery.exact(index.Schema().PropertyId, "The value is irrelevant, we just want to perform some sort of lookup against this " + "index"));
                }
                // then let another thread come in and create a node
                Threads.execute(Db =>
                {
                    using (Transaction transaction = Db.beginTx())
                    {
                        Db.createNode(label).setProperty(propertyKey, conflictingValue);
                        transaction.success();
                    }
                    return(null);
                }, graphDb).get();

                // before we create a node with the same property ourselves - using the same statement that we have
                // already used for lookup against that very same index
                long node = ktx.DataWrite().nodeCreate();
                ktx.DataWrite().nodeAddLabel(node, labelId);
                try
                {
                    ktx.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of(conflictingValue));

                    fail("exception expected");
                }
                // Then
                catch (UniquePropertyValueValidationException e)
                {
                    assertEquals(ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyKeyId), e.Constraint());
                    IndexEntryConflictException conflict = Iterators.single(e.Conflicts().GetEnumerator());
                    assertEquals(Values.stringValue(conflictingValue), conflict.SinglePropertyValue);
                }

                tx.Success();
            }
        }
 protected internal override ResourceIterator <Relationship> ExpandRelationshipsWithoutChecks(PathExpander expander)
 {
     System.Collections.IEnumerable expandIterable = expander.expand(this, this);
     return(Iterators.asResourceIterator(expandIterable.GetEnumerator()));
 }