예제 #1
0
        /// <summary>
        /// The problem would manifest even if the transaction was performed on the Master, it would then occur when the
        /// Slave pulls updates and tries to apply the transaction. The reason for the test to run transactions against the
        /// Slave is because it makes guarantees for when the master has to apply the transaction.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDeleteRecords()
        public virtual void ShouldDeleteRecords()
        {
            // given
            ManagedCluster cluster = ClusterRule.startCluster();

            HighlyAvailableGraphDatabase master = cluster.Master;
            HighlyAvailableGraphDatabase slave  = cluster.AnySlave;

            Relationship rel;

            using (Transaction tx = slave.BeginTx())
            {
                rel = slave.CreateNode().createRelationshipTo(slave.CreateNode(), withName("FOO"));
                tx.Success();
            }

            using (Transaction transaction = master.BeginTx())
            {
                assertNotNull(master.GetRelationshipById(rel.Id));
            }

            // when
            using (Transaction tx = slave.BeginTx())
            {
                rel.Delete();
                tx.Success();
            }

            // then - there should have been no exceptions
            slave.Shutdown();
            master.Shutdown();
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testConflictingIdDoesNotSilentlyFail()
        public virtual void TestConflictingIdDoesNotSilentlyFail()
        {
            HighlyAvailableGraphDatabase master     = null;
            HighlyAvailableGraphDatabase dbWithId21 = null;
            HighlyAvailableGraphDatabase dbWithId22 = null;

            try
            {
                int masterClusterPort = PortAuthority.allocatePort();

                GraphDatabaseBuilder masterBuilder = (new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(Path(1)).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:" + masterClusterPort).setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + masterClusterPort).setConfig(ClusterSettings.server_id, "" + 1).setConfig(HaSettings.HaServer, ":" + PortAuthority.allocatePort()).setConfig(HaSettings.TxPushFactor, "0").setConfig(OnlineBackupSettings.online_backup_enabled, false.ToString());
                master = ( HighlyAvailableGraphDatabase )masterBuilder.NewGraphDatabase();

                GraphDatabaseBuilder db21Builder = (new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(Path(2)).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:" + masterClusterPort).setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(ClusterSettings.server_id, "" + 2).setConfig(HaSettings.HaServer, ":" + PortAuthority.allocatePort()).setConfig(HaSettings.TxPushFactor, "0").setConfig(OnlineBackupSettings.online_backup_enabled, false.ToString());
                dbWithId21 = ( HighlyAvailableGraphDatabase )db21Builder.NewGraphDatabase();

                GraphDatabaseBuilder db22Builder = (new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(Path(3)).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:" + masterClusterPort).setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(ClusterSettings.server_id, "" + 2).setConfig(HaSettings.HaServer, ":" + PortAuthority.allocatePort()).setConfig(HaSettings.TxPushFactor, "0").setConfig(OnlineBackupSettings.online_backup_enabled, false.ToString());

                try
                {
                    dbWithId22 = ( HighlyAvailableGraphDatabase )db22Builder.NewGraphDatabase();
                    fail("Should not be able to startup when a cluster already has my id");
                }
                catch (Exception)
                {
                    // awesome
                }

                assertTrue(master.Master);
                assertTrue(!dbWithId21.Master);

                using (Transaction transaction = dbWithId21.BeginTx())
                {
                    transaction.Success();
                }
            }
            finally
            {
                if (dbWithId21 != null)
                {
                    dbWithId21.Shutdown();
                }
                if (dbWithId22 != null)
                {
                    dbWithId22.Shutdown();
                }
                if (master != null)
                {
                    master.Shutdown();
                }
            }
        }
예제 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testMasterSwitchHappensOnKillMinus9() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestMasterSwitchHappensOnKillMinus9()
        {
            Process proc = null;
            HighlyAvailableGraphDatabase dbWithId2 = null;
            HighlyAvailableGraphDatabase dbWithId3 = null;
            HighlyAvailableGraphDatabase oldMaster = null;

            int clusterPort1 = PortAuthority.allocatePort();
            int clusterPort2 = PortAuthority.allocatePort();
            int clusterPort3 = PortAuthority.allocatePort();

            int haPort1 = PortAuthority.allocatePort();
            int haPort2 = PortAuthority.allocatePort();
            int haPort3 = PortAuthority.allocatePort();

            try
            {
                proc      = Run(1, clusterPort1, haPort1, clusterPort1, clusterPort2);
                dbWithId2 = StartDb(2, Path(2), clusterPort2, haPort2, clusterPort1, clusterPort2);
                dbWithId3 = StartDb(3, Path(3), clusterPort3, haPort3, clusterPort1, clusterPort2);

                WaitUntilAllProperlyAvailable(dbWithId2, 1, MASTER, 2, SLAVE, 3, SLAVE);
                WaitUntilAllProperlyAvailable(dbWithId3, 1, MASTER, 2, SLAVE, 3, SLAVE);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch newMasterAvailableLatch = new java.util.concurrent.CountDownLatch(1);
                System.Threading.CountdownEvent newMasterAvailableLatch = new System.Threading.CountdownEvent(1);
                dbWithId2.DependencyResolver.resolveDependency(typeof(ClusterClient)).addAtomicBroadcastListener(value =>
                {
                    try
                    {
                        object @event = (new AtomicBroadcastSerializer(new ObjectStreamFactory(), new ObjectStreamFactory())).receive(value);
                        if (@event is MemberIsAvailable)
                        {
                            if (HighAvailabilityModeSwitcher.MASTER.Equals((( MemberIsAvailable )@event).Role))
                            {
                                newMasterAvailableLatch.Signal();
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        fail(e.ToString());
                    }
                });
                proc.destroy();
                proc = null;

                assertTrue(newMasterAvailableLatch.await(60, SECONDS));

                assertTrue(dbWithId2.Master);
                assertTrue(!dbWithId3.Master);

                // Ensure that everyone has marked the killed instance as failed, otherwise it cannot rejoin
                WaitUntilAllProperlyAvailable(dbWithId2, 1, UNKNOWN, 2, MASTER, 3, SLAVE);
                WaitUntilAllProperlyAvailable(dbWithId3, 1, UNKNOWN, 2, MASTER, 3, SLAVE);

                oldMaster = StartDb(1, Path(1), clusterPort1, haPort1, clusterPort1, clusterPort2);
                long oldMasterNode = CreateNamedNode(oldMaster, "Old master");
                assertEquals(oldMasterNode, GetNamedNode(dbWithId2, "Old master"));
            }
            finally
            {
                if (proc != null)
                {
                    proc.destroy();
                }
                if (oldMaster != null)
                {
                    oldMaster.Shutdown();
                }
                if (dbWithId2 != null)
                {
                    dbWithId2.Shutdown();
                }
                if (dbWithId3 != null)
                {
                    dbWithId3.Shutdown();
                }
            }
        }