Пример #1
0
 private void LoadNode(GraphDatabaseAPI db, Node node)
 {
     using (Transaction ignored = Db.beginTx())
     {
         Iterables.count(node.Relationships);
     }
 }
Пример #2
0
        private void AttemptAndFailConstraintCreation()
        {
            using (Transaction tx = Db.beginTx())
            {
                for (int i = 0; i < 2; i++)
                {
                    Node node1 = Db.createNode(_label);
                    node1.SetProperty("prop", true);
                }

                tx.Success();
            }

            // when
            try
            {
                using (Transaction tx = Db.beginTx())
                {
                    Db.schema().constraintFor(_label).assertPropertyIsUnique("prop").create();
                    fail("Should have failed with ConstraintViolationException");
                    tx.Success();
                }
            }
            catch (ConstraintViolationException)
            {
            }

            // then
            using (Transaction ignore = Db.beginTx())
            {
                assertEquals(0, Iterables.count(Db.schema().Indexes));
            }
        }
Пример #3
0
//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)));
            }
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeNewLabeledNodeInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeNewLabeledNodeInTransaction()
        {
            long         nodeId;
            int          labelId;
            const string labelName = "Town";

            using (Transaction tx = beginTransaction())
            {
                nodeId  = tx.DataWrite().nodeCreate();
                labelId = tx.Token().labelGetOrCreateForName(labelName);
                tx.DataWrite().nodeAddLabel(nodeId, labelId);

                using (NodeCursor node = tx.Cursors().allocateNodeCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertTrue("should access node", node.Next());

                    LabelSet labels = node.Labels();
                    assertEquals(1, labels.NumberOfLabels());
                    assertEquals(labelId, labels.Label(0));
                    assertTrue(node.HasLabel(labelId));
                    assertFalse(node.HasLabel(labelId + 1));
                    assertFalse("should only find one node", node.Next());
                }
                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignore = graphDb.beginTx())
            {
                assertThat(graphDb.getNodeById(nodeId).Labels, equalTo(Iterables.iterable(label(labelName))));
            }
        }
Пример #5
0
        public override bool HasQuorum()
        {
            int availableMembers = ( int )Iterables.count(_heartbeatContext.Alive);
            int totalMembers     = CommonState.configuration().Members.Count;

            return(Quorums.isQuorum(availableMembers, totalMembers));
        }
Пример #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void snapshotListPrunesOtherMemberWithSameMasterRole() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SnapshotListPrunesOtherMemberWithSameMasterRole()
        {
            // GIVEN
            // -- a snapshot containing one member with a role
            PaxosClusterMemberEvents.ClusterMembersSnapshot snapshot = new PaxosClusterMemberEvents.ClusterMembersSnapshot(new HANewSnapshotFunction());
            URI               clusterUri = new URI(URI);
            InstanceId        instanceId = new InstanceId(1);
            MemberIsAvailable @event     = new MemberIsAvailable(MASTER, instanceId, clusterUri, new URI(URI + "?something1"), DEFAULT);

            snapshot.AvailableMember(@event);

            // WHEN
            // -- another member, but with same role, gets added to the snapshot
            URI               otherClusterUri = new URI(URI);
            InstanceId        otherInstanceId = new InstanceId(2);
            MemberIsAvailable otherEvent      = new MemberIsAvailable(MASTER, otherInstanceId, otherClusterUri, new URI(URI + "?something2"), DEFAULT);

            snapshot.AvailableMember(otherEvent);

            // THEN
            // -- getting the snapshot list should only reveal the last member added, as it had the same role
            assertEquals(1, Iterables.count(snapshot.GetCurrentAvailable(otherInstanceId)));
            assertThat(snapshot.GetCurrentAvailable(otherInstanceId), hasItems(MemberIsAvailable(otherEvent)));
            assertEquals(1, Iterables.count(snapshot.CurrentAvailableMembers));
            assertThat(snapshot.CurrentAvailableMembers, hasItems(MemberIsAvailable(otherEvent)));
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Test public void shouldExpandOnFirstAccess()
        public virtual void ShouldExpandOnFirstAccess()
        {
            // GIVEN
            TraversalBranch     parent = mock(typeof(TraversalBranch));
            Node                source = mock(typeof(Node));
            TraversalBranchImpl branch = new TraversalBranchImpl(parent, source);
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("rawtypes") org.neo4j.graphdb.PathExpander expander = mock(org.neo4j.graphdb.PathExpander.class);
            PathExpander expander = mock(typeof(PathExpander));

            when(expander.expand(eq(branch), any(typeof(BranchState)))).thenReturn(Iterables.emptyResourceIterable());
            TraversalContext context = mock(typeof(TraversalContext));

            when(context.Evaluate(eq(branch), Null)).thenReturn(INCLUDE_AND_CONTINUE);

            // WHEN initializing
            branch.Initialize(expander, context);

            // THEN the branch should not be expanded
            verifyZeroInteractions(source);

            // and WHEN actually traversing from it
            branch.Next(expander, context);

            // THEN we should expand it
            verify(expander).expand(any(typeof(Path)), any(typeof(BranchState)));
        }
Пример #8
0
//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)));
            }
        }
Пример #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testTraverseRelationshipsWithStartNodeNotIncluded()
        public virtual void TestTraverseRelationshipsWithStartNodeNotIncluded()
        {
            using (Transaction transaction = BeginTx())
            {
                TraversalDescription traversal = GraphDb.traversalDescription().evaluator(excludeStartPosition());
                assertEquals(1, Iterables.count(traversal.Traverse(Node("1")).relationships()));
            }
        }
        private long NodeCount()
        {
            Transaction transaction = _db.beginTx();
            long        count       = Iterables.count(_db.AllNodes);

            transaction.Close();
            return(count);
        }
Пример #11
0
 private void Execute(TraversalDescription traversal, Uniqueness uniqueness)
 {
     using (Transaction transaction = BeginTx())
     {
         Traverser traverser = traversal.Uniqueness(uniqueness).traverse(Node("1"));
         assertNotEquals("empty traversal", 0, Iterables.count(traverser));
     }
 }
        private long DoneBatches(StageExecution execution)
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: Step<?> step = org.neo4j.helpers.collection.Iterables.last(execution.steps());
            Step <object> step = Iterables.last(execution.Steps());

            return(step.Stats().stat(Keys.done_batches).asLong());
        }
Пример #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldServiceLoaderFindCypherEngineProvider()
        public virtual void ShouldServiceLoaderFindCypherEngineProvider()
        {
            // WHEN
            ServiceLoader <QueryEngineProvider> services = ServiceLoader.load(typeof(QueryEngineProvider));

            // THEN
            assertTrue(Iterables.single(services) is CommunityCypherEngineProvider);
        }
Пример #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void copyConstructor()
        internal virtual void CopyConstructor()
        {
            Listeners <Listener> original = NewListeners(new Listener(), new Listener(), new Listener());

            Listeners <Listener> copy = new Listeners <Listener>(original);

            assertEquals(Iterables.asList(original), Iterables.asList(copy));
        }
Пример #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void listenersIterable()
        internal virtual void ListenersIterable()
        {
            Listener listener1 = new Listener();
            Listener listener2 = new Listener();
            Listener listener3 = new Listener();

            Listeners <Listener> listeners = NewListeners(listener1, listener2, listener3);

            assertEquals(Arrays.asList(listener1, listener2, listener3), Iterables.asList(listeners));
        }
Пример #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("boxing") @Override public Void beforeCommit(org.neo4j.graphdb.event.TransactionData data)
            public override Void BeforeCommit(TransactionData data)
            {
                if (Iterables.count(data.CreatedRelationships()) == 0)
                {
                    return(null);
                }

                Node.setProperty("counter", (( long? )Node.removeProperty("counter")) + 1);
                return(null);
            }
Пример #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void add()
        internal virtual void Add()
        {
            Listener[] listenersArray = new Listener[]
            {
                new Listener(),
                new Listener(),
                new Listener()
            };

            Listeners <Listener> listeners = NewListeners(listenersArray);

            assertArrayEquals(listenersArray, Iterables.asArray(typeof(Listener), listeners));
        }
Пример #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDropSchemaRuleFromStore() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDropSchemaRuleFromStore()
        {
            // GIVEN
            SchemaRecord beforeRecords = Serialize(_rule, _id, true, true);
            SchemaRecord afterRecords  = Serialize(_rule, _id, false, false);

            when(_neoStores.SchemaStore).thenReturn(_schemaStore);

            // WHEN
            VisitSchemaRuleCommand(_storeApplier, new Command.SchemaRuleCommand(beforeRecords, afterRecords, _rule));

            // THEN
            verify(_schemaStore).updateRecord(Iterables.first(afterRecords));
        }
Пример #19
0
        public override ProtocolServer NewProtocolServer(InstanceId me, TimeoutStrategy timeoutStrategy, MessageSource input, MessageSender output, AcceptorInstanceStore acceptorInstanceStore, ElectionCredentialsProvider electionCredentialsProvider, Executor stateMachineExecutor, ObjectInputStreamFactory objectInputStreamFactory, ObjectOutputStreamFactory objectOutputStreamFactory, Config config)
        {
            DelayedDirectExecutor executor = new DelayedDirectExecutor(_logging);

            // Create state machines
            Timeouts timeouts = new Timeouts(timeoutStrategy);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext context = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext(me, org.neo4j.helpers.collection.Iterables.iterable(new org.neo4j.cluster.protocol.election.ElectionRole(org.neo4j.cluster.protocol.cluster.ClusterConfiguration.COORDINATOR)), new org.neo4j.cluster.protocol.cluster.ClusterConfiguration(initialConfig.getName(), logging, initialConfig.getMemberURIs()), executor, logging, objectInputStreamFactory, objectOutputStreamFactory, acceptorInstanceStore, timeouts, electionCredentialsProvider, config);
            MultiPaxosContext context = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(ClusterConfiguration.COORDINATOR)), new ClusterConfiguration(_initialConfig.Name, _logging, _initialConfig.MemberURIs), executor, _logging, objectInputStreamFactory, objectOutputStreamFactory, acceptorInstanceStore, timeouts, electionCredentialsProvider, config);

            SnapshotContext snapshotContext = new SnapshotContext(context.ClusterContext, context.LearnerContext);

            return(NewProtocolServer(me, input, output, stateMachineExecutor, executor, timeouts, context, snapshotContext));
        }
Пример #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateUniquenessConstraint()
        public virtual void ShouldCreateUniquenessConstraint()
        {
            // WHEN
            ConstraintDefinition constraint = CreateUniquenessConstraint(_label, _propertyKey);

            // THEN
            using (Transaction tx = _db.beginTx())
            {
                assertEquals(ConstraintType.UNIQUENESS, constraint.ConstraintType);

                assertEquals(_label.name(), constraint.Label.name());
                assertEquals(asSet(_propertyKey), Iterables.asSet(constraint.PropertyKeys));
                tx.Success();
            }
        }
Пример #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void remove()
        internal virtual void Remove()
        {
            Listener listener1 = new Listener();
            Listener listener2 = new Listener();
            Listener listener3 = new Listener();

            Listeners <Listener> listeners = NewListeners(listener1, listener2, listener3);

            assertEquals(Arrays.asList(listener1, listener2, listener3), Iterables.asList(listeners));

            listeners.Remove(listener1);
            assertEquals(Arrays.asList(listener2, listener3), Iterables.asList(listeners));

            listeners.Remove(listener3);
            assertEquals(singletonList(listener2), Iterables.asList(listeners));
        }
Пример #22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSetLatestConstraintRule() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSetLatestConstraintRule()
        {
            // Given
            SchemaRecord beforeRecords = Serialize(_rule, _id, true, true);
            SchemaRecord afterRecords  = Serialize(_rule, _id, true, false);

            when(_neoStores.SchemaStore).thenReturn(_schemaStore);
            when(_neoStores.MetaDataStore).thenReturn(_metaDataStore);

            ConstraintRule schemaRule = ConstraintRule.constraintRule(_id, ConstraintDescriptorFactory.uniqueForLabel(_labelId, _propertyKey), 0);

            // WHEN
            VisitSchemaRuleCommand(_storeApplier, new Command.SchemaRuleCommand(beforeRecords, afterRecords, schemaRule));

            // THEN
            verify(_schemaStore).updateRecord(Iterables.first(afterRecords));
            verify(_metaDataStore).LatestConstraintIntroducingTx = _txId;
        }
Пример #23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void settingLastLearnedInstanceToNegativeOneShouldAlwaysWin()
        public virtual void SettingLastLearnedInstanceToNegativeOneShouldAlwaysWin()
        {
            // Given
            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10);

            MultiPaxosContext mpCtx = new MultiPaxosContext(null, Iterables.empty(), mock(typeof(ClusterConfiguration)), null, NullLogProvider.Instance, null, null, null, null, null, config);
            LearnerContext    state = mpCtx.LearnerContext;

            // When
            state.SetLastKnownLearnedInstanceInCluster(1, new InstanceId(2));
            state.SetLastKnownLearnedInstanceInCluster(-1, null);

            // Then
            assertThat(state.LastKnownLearnedInstanceInCluster, equalTo(-1L));
            assertThat(state.LastKnownAliveUpToDateInstance, equalTo(new InstanceId(2)));
        }
Пример #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldOnlyAllowHigherLastLearnedInstanceId()
        public virtual void ShouldOnlyAllowHigherLastLearnedInstanceId()
        {
            // Given

            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10);

            MultiPaxosContext mpCtx = new MultiPaxosContext(null, Iterables.empty(), mock(typeof(ClusterConfiguration)), null, NullLogProvider.Instance, null, null, null, null, null, config);
            LearnerContext    state = mpCtx.LearnerContext;

            // When
            state.SetLastKnownLearnedInstanceInCluster(1, new InstanceId(2));
            state.SetLastKnownLearnedInstanceInCluster(0, new InstanceId(3));

            // Then
            assertThat(state.LastKnownLearnedInstanceInCluster, equalTo(1L));
        }
Пример #25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void ensureCorrectPathEntitiesInShortPath()
        public virtual void EnsureCorrectPathEntitiesInShortPath()
        {
            /*
             * (a)-->(b)
             */
            CreateGraph("a TO b");

            Node         a    = GetNodeWithName("a");
            Node         b    = GetNodeWithName("b");
            Relationship r    = a.GetSingleRelationship(To, OUTGOING);
            Path         path = Iterables.single(GraphDb.bidirectionalTraversalDescription().mirroredSides(GraphDb.traversalDescription().relationships(To, OUTGOING).uniqueness(NODE_PATH)).collisionEvaluator(Evaluators.atDepth(1)).sideSelector(SideSelectorPolicies.LEVEL, 1).traverse(a, b));

            AssertContainsInOrder(path.Nodes(), a, b);
            AssertContainsInOrder(path.ReverseNodes(), b, a);
            AssertContainsInOrder(path.Relationships(), r);
            AssertContainsInOrder(path.ReverseRelationships(), r);
            AssertContainsInOrder(path, a, r, b);
            assertEquals(a, path.StartNode());
            assertEquals(b, path.EndNode());
            assertEquals(r, path.LastRelationship());
        }
Пример #26
0
        private RecordStorageEngine Get(FileSystemAbstraction fs, PageCache pageCache, IndexProvider indexProvider, DatabaseHealth databaseHealth, DatabaseLayout databaseLayout, System.Func <BatchTransactionApplierFacade, BatchTransactionApplierFacade> transactionApplierTransformer, Monitors monitors, LockService lockService)
        {
            IdGeneratorFactory    idGeneratorFactory          = new EphemeralIdGenerator.Factory();
            ExplicitIndexProvider explicitIndexProviderLookup = mock(typeof(ExplicitIndexProvider));

            when(explicitIndexProviderLookup.AllIndexProviders()).thenReturn(Iterables.empty());
            IndexConfigStore indexConfigStore = new IndexConfigStore(databaseLayout, fs);
            JobScheduler     scheduler        = _life.add(createScheduler());
            Config           config           = Config.defaults(GraphDatabaseSettings.default_schema_provider, indexProvider.ProviderDescriptor.name());

            Dependencies dependencies = new Dependencies();

            dependencies.SatisfyDependency(indexProvider);

            BufferingIdGeneratorFactory bufferingIdGeneratorFactory = new BufferingIdGeneratorFactory(idGeneratorFactory, Org.Neo4j.Kernel.impl.store.id.IdReuseEligibility_Fields.Always, new CommunityIdTypeConfigurationProvider());
            DefaultIndexProviderMap     indexProviderMap            = new DefaultIndexProviderMap(dependencies, config);
            NullLogProvider             nullLogProvider             = NullLogProvider.Instance;

            _life.add(indexProviderMap);
            return(_life.add(new ExtendedRecordStorageEngine(databaseLayout, config, pageCache, fs, nullLogProvider, nullLogProvider, mockedTokenHolders(), mock(typeof(SchemaState)), new StandardConstraintSemantics(), scheduler, mock(typeof(TokenNameLookup)), lockService, indexProviderMap, IndexingService.NO_MONITOR, databaseHealth, explicitIndexProviderLookup, indexConfigStore, new SynchronizedArrayIdOrderingQueue(), idGeneratorFactory, new BufferedIdController(bufferingIdGeneratorFactory, scheduler), transactionApplierTransformer, monitors, RecoveryCleanupWorkCollector.immediate(), OperationalMode.single)));
        }
Пример #27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void snapshotListDoesNotPruneOtherMemberWithSlaveRole() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SnapshotListDoesNotPruneOtherMemberWithSlaveRole()
        {
            // GIVEN
            // -- a snapshot containing one member with a role
            PaxosClusterMemberEvents.ClusterMembersSnapshot snapshot = new PaxosClusterMemberEvents.ClusterMembersSnapshot(new HANewSnapshotFunction());
            URI               clusterUri = new URI(URI);
            InstanceId        instanceId = new InstanceId(1);
            MemberIsAvailable @event     = new MemberIsAvailable(SLAVE, instanceId, clusterUri, new URI(URI + "?something1"), DEFAULT);

            snapshot.AvailableMember(@event);

            // WHEN
            // -- another member, but with same role, gets added to the snapshot
            URI               otherClusterUri = new URI(URI);
            InstanceId        otherInstanceId = new InstanceId(2);
            MemberIsAvailable otherEvent      = new MemberIsAvailable(SLAVE, otherInstanceId, otherClusterUri, new URI(URI + "?something2"), DEFAULT);

            snapshot.AvailableMember(otherEvent);

            // THEN
            assertEquals(2, Iterables.count(snapshot.CurrentAvailableMembers));
            assertThat(snapshot.CurrentAvailableMembers, hasItems(MemberIsAvailable(@event), MemberIsAvailable(otherEvent)));
        }
Пример #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void snapshotListPrunesSameMemberOnIdenticalAvailabilityEvents() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SnapshotListPrunesSameMemberOnIdenticalAvailabilityEvents()
        {
            // GIVEN
            // -- a snapshot containing one member with a role
            PaxosClusterMemberEvents.ClusterMembersSnapshot snapshot = new PaxosClusterMemberEvents.ClusterMembersSnapshot(new PaxosClusterMemberEvents.UniqueRoleFilter()
                                                                                                                           );
            URI               clusterUri        = new URI(URI);
            InstanceId        instanceId        = new InstanceId(1);
            MemberIsAvailable memberIsAvailable = new MemberIsAvailable(MASTER, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);

            snapshot.AvailableMember(memberIsAvailable);

            // WHEN
            // -- the same member and role gets added to the snapshot
            snapshot.AvailableMember(memberIsAvailable);

            // THEN
            // -- getting the snapshot list should only reveal the last one
            assertEquals(1, Iterables.count(snapshot.GetCurrentAvailable(instanceId)));
            assertThat(snapshot.GetCurrentAvailable(instanceId), hasItem(memberIsAvailable(memberIsAvailable)));
            assertEquals(1, Iterables.count(snapshot.CurrentAvailableMembers));
            assertThat(snapshot.CurrentAvailableMembers, hasItems(memberIsAvailable(memberIsAvailable)));
        }
Пример #29
0
//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)));
            }
        }
Пример #30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromMasterToSlave() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SnapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromMasterToSlave()
        {
            // GIVEN
            // -- a snapshot containing one member with a role
            PaxosClusterMemberEvents.ClusterMembersSnapshot snapshot = new PaxosClusterMemberEvents.ClusterMembersSnapshot(new HANewSnapshotFunction());
            URI               clusterUri = new URI(URI);
            InstanceId        instanceId = new InstanceId(1);
            MemberIsAvailable event1     = new MemberIsAvailable(MASTER, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);

            snapshot.AvailableMember(event1);

            // WHEN
            // -- the same member, although different role, gets added to the snapshot
            MemberIsAvailable event2 = new MemberIsAvailable(SLAVE, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);

            snapshot.AvailableMember(event2);

            // THEN
            // -- getting the snapshot list should reveal both
            assertEquals(1, Iterables.count(snapshot.GetCurrentAvailable(instanceId)));
            assertThat(snapshot.GetCurrentAvailable(instanceId), hasItems(MemberIsAvailable(event2)));
            assertEquals(1, Iterables.count(snapshot.CurrentAvailableMembers));
            assertThat(snapshot.CurrentAvailableMembers, hasItems(MemberIsAvailable(event2)));
        }