Esempio n. 1
0
        public override bool HasQuorum()
        {
            int availableMembers = ( int )Iterables.count(_heartbeatContext.Alive);
            int totalMembers     = CommonState.configuration().Members.Count;

            return(Quorums.isQuorum(availableMembers, totalMembers));
        }
Esempio n. 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));
            }
        }
Esempio n. 3
0
 private void LoadNode(GraphDatabaseAPI db, Node node)
 {
     using (Transaction ignored = Db.beginTx())
     {
         Iterables.count(node.Relationships);
     }
 }
Esempio n. 4
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)));
        }
        private long NodeCount()
        {
            Transaction transaction = _db.beginTx();
            long        count       = Iterables.count(_db.AllNodes);

            transaction.Close();
            return(count);
        }
Esempio n. 6
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()));
            }
        }
Esempio n. 7
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));
     }
 }
Esempio n. 8
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);
            }
Esempio n. 9
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)));
        }
Esempio n. 10
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)));
        }
Esempio n. 11
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)));
        }
Esempio n. 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveAvailableOrphanedConstraintIndexIfUniqueConstraintCreationFails()
        public virtual void ShouldHaveAvailableOrphanedConstraintIndexIfUniqueConstraintCreationFails()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction fs = fileSystemRule.get();
            EphemeralFileSystemAbstraction fs = FileSystemRule.get();

            fs.Mkdir(new File("/tmp"));
            File pathToDb = new File("/tmp/bar2");

            TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory();

            dbFactory.FileSystem = fs;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction[] storeInNeedOfRecovery = new org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction[1];
            EphemeralFileSystemAbstraction[] storeInNeedOfRecovery = new EphemeralFileSystemAbstraction[1];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean monitorCalled = new java.util.concurrent.atomic.AtomicBoolean(false);
            AtomicBoolean monitorCalled = new AtomicBoolean(false);

            Monitors monitors = new Monitors();

            monitors.AddMonitorListener(new MonitorAdapterAnonymousInnerClass(this, fs, storeInNeedOfRecovery, monitorCalled));
            dbFactory.Monitors = monitors;

            // This test relies on behaviour that is specific to the Lucene populator, where uniqueness is controlled
            // after index has been populated, which is why we're using NATIVE20 and index booleans (they end up in Lucene)
            _db = ( GraphDatabaseAPI )dbFactory.NewImpermanentDatabaseBuilder(pathToDb).setConfig(default_schema_provider, NATIVE20.providerName()).newGraphDatabase();

            using (Transaction tx = _db.beginTx())
            {
                for (int i = 0; i < 2; i++)
                {
                    _db.createNode(_label).setProperty(KEY, true);
                }

                tx.Success();
            }

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

            _db.shutdown();

            assertTrue(monitorCalled.get());

            // when
            dbFactory            = new TestGraphDatabaseFactory();
            dbFactory.FileSystem = storeInNeedOfRecovery[0];
            _db = ( GraphDatabaseAPI )dbFactory.NewImpermanentDatabase(pathToDb);

            // then
            using (Transaction ignore = _db.beginTx())
            {
                _db.schema().awaitIndexesOnline(10, TimeUnit.SECONDS);
            }

            using (Transaction ignore = _db.beginTx())
            {
                assertEquals(2, Iterables.count(_db.AllNodes));
            }

            using (Transaction ignore = _db.beginTx())
            {
                assertEquals(0, Iterables.count(Iterables.asList(_db.schema().Constraints)));
            }

            using (Transaction ignore = _db.beginTx())
            {
                IndexDefinition orphanedConstraintIndex = single(_db.schema().Indexes);
                assertEquals(_label.name(), single(orphanedConstraintIndex.Labels).name());
                assertEquals(KEY, single(orphanedConstraintIndex.PropertyKeys));
            }

            _db.shutdown();
        }