Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test @Ignore public void slaveShouldServeTxsAfterMasterLostQuorumWentToPendingAndThenQuorumWasRestored() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SlaveShouldServeTxsAfterMasterLostQuorumWentToPendingAndThenQuorumWasRestored()
        {
            // GIVEN: cluster with 3 members
            HighlyAvailableGraphDatabase master = _cluster.Master;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final HighlyAvailableGraphDatabase slave1 = cluster.getAnySlave();
            HighlyAvailableGraphDatabase slave1 = _cluster.AnySlave;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final HighlyAvailableGraphDatabase slave2 = cluster.getAnySlave(slave1);
            HighlyAvailableGraphDatabase slave2 = _cluster.getAnySlave(slave1);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch slave1Left = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent slave1Left = new System.Threading.CountdownEvent(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch slave2Left = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent slave2Left = new System.Threading.CountdownEvent(1);

            ClusterClientOf(master).addHeartbeatListener(new HeartbeatListener_AdapterAnonymousInnerClass(this, slave1, slave2, slave1Left, slave2Left));

            // fail slave1 and await master to spot the failure
            ClusterManager.RepairKit slave1RepairKit = _cluster.fail(slave1);
            assertTrue(slave1Left.await(60, SECONDS));

            // fail slave2 and await master to spot the failure
            ClusterManager.RepairKit slave2RepairKit = _cluster.fail(slave2);
            assertTrue(slave2Left.await(60, SECONDS));

            // master loses quorum and goes to PENDING, cluster is unavailable
            _cluster.await(masterAvailable().negate());
            assertEquals(HighAvailabilityMemberState.PENDING, master.InstanceState);

            // WHEN: both slaves are repaired, majority restored, quorum can be achieved
            slave1RepairKit.Repair();
            slave2RepairKit.Repair();

            // whole cluster looks fine, but slaves have stale value of the epoch if they rejoin the cluster in SLAVE state
            _cluster.await(masterAvailable());
            _cluster.await(masterSeesSlavesAsAvailable(2));
            HighlyAvailableGraphDatabase newMaster = _cluster.Master;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final HighlyAvailableGraphDatabase newSlave1 = cluster.getAnySlave();
            HighlyAvailableGraphDatabase newSlave1 = _cluster.AnySlave;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final HighlyAvailableGraphDatabase newSlave2 = cluster.getAnySlave(newSlave1);
            HighlyAvailableGraphDatabase newSlave2 = _cluster.getAnySlave(newSlave1);

            // now adding another failing listener and wait for the failure due to stale epoch
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch slave1Unavailable = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent slave1Unavailable = new System.Threading.CountdownEvent(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch slave2Unavailable = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent slave2Unavailable = new System.Threading.CountdownEvent(1);
            ClusterMemberEvents             clusterEvents     = newMaster.DependencyResolver.resolveDependency(typeof(ClusterMemberEvents));

            clusterEvents.AddClusterMemberListener(new ClusterMemberListener_AdapterAnonymousInnerClass(this, newSlave1, newSlave2, slave1Unavailable, slave2Unavailable));

            // attempt to perform transactions on both slaves throws, election is triggered
            AttemptTransactions(newSlave1, newSlave2);
            // set a timeout in case the instance does not have stale epoch
            assertTrue(slave1Unavailable.await(60, TimeUnit.SECONDS));
            assertTrue(slave2Unavailable.await(60, TimeUnit.SECONDS));

            // THEN: done with election, cluster feels good and able to serve transactions
            _cluster.info("Waiting for cluster to stabilize");
            _cluster.await(allSeesAllAsAvailable());

            _cluster.info("Assert ok");
            assertNotNull(CreateNodeOn(newMaster));
            assertNotNull(CreateNodeOn(newSlave1));
            assertNotNull(CreateNodeOn(newSlave2));
        }