Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testBasicPropagationFromSlaveToMaster()
        public virtual void TestBasicPropagationFromSlaveToMaster()
        {
            // given
            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
            HighlyAvailableGraphDatabase  master  = cluster.Master;
            HighlyAvailableGraphDatabase  slave   = cluster.AnySlave;
            long nodeId;

            // a node with a property
            using (Transaction tx = master.BeginTx())
            {
                Node node = master.CreateNode();
                nodeId = node.Id;
                node.SetProperty("foo", "bar");
                tx.Success();
            }

            cluster.Sync();

            // when
            // the slave does a change
            using (Transaction tx = slave.BeginTx())
            {
                slave.GetNodeById(nodeId).setProperty("foo", "bar2");
                tx.Success();
            }

            // then
            // the master must pick up the change
            using (Transaction tx = master.BeginTx())
            {
                assertEquals("bar2", master.GetNodeById(nodeId).getProperty("foo"));
                tx.Success();
            }
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testBasicFailover() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestBasicFailover()
        {
            // given
            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
            HighlyAvailableGraphDatabase  master  = cluster.Master;
            HighlyAvailableGraphDatabase  slave1  = cluster.AnySlave;
            HighlyAvailableGraphDatabase  slave2  = cluster.GetAnySlave(slave1);

            // When
            long start = System.nanoTime();

            ClusterManager.RepairKit repair = cluster.Shutdown(master);
            try
            {
                Logger.Logger.warning("Shut down master");
                cluster.Await(ClusterManager.masterAvailable());
                long end = System.nanoTime();
                Logger.Logger.warning("Failover took:" + (end - start) / 1000000 + "ms");
                // Then
                bool slave1Master = slave1.Master;
                bool slave2Master = slave2.Master;
                if (slave1Master)
                {
                    assertFalse(slave2Master);
                }
                else
                {
                    assertTrue(slave2Master);
                }
            }
            finally
            {
                repair.Repair();
            }
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testBasicPropagationFromMasterToSlave()
        public virtual void TestBasicPropagationFromMasterToSlave()
        {
            // given
            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
            long nodeId = 4;
            HighlyAvailableGraphDatabase master = cluster.Master;

            using (Transaction tx = master.BeginTx())
            {
                Node node = master.CreateNode();
                node.SetProperty("Hello", "World");
                nodeId = node.Id;

                tx.Success();
            }

            cluster.Sync();

            // No need to wait, the push factor is 2
            HighlyAvailableGraphDatabase slave1 = cluster.AnySlave;

            CheckNodeOnSlave(nodeId, slave1);

            HighlyAvailableGraphDatabase slave2 = cluster.GetAnySlave(slave1);

            CheckNodeOnSlave(nodeId, slave2);
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp()
        public virtual void SetUp()
        {
            TestHighlyAvailableGraphDatabaseFactory factory = new TestHighlyAvailableGraphDatabaseFactory();
            Monitors monitors = new Monitors();

            monitors.AddMonitorListener(_monitor);
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            factory.RemoveKernelExtensions(extension => extension.GetType().FullName.Contains("LabelScan"));
            ClusterManager clusterManager = (new ClusterManager.Builder(TestDirectory.directory("root"))).withDbFactory(factory).withMonitors(monitors).withStoreDirInitializer((serverId, storeDir) =>
            {
                if (serverId == 1)
                {
                    GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(storeDir).setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase();
                    try
                    {
                        CreateSomeLabeledNodes(db, new Label[] { Labels.First }, new Label[] { Labels.First, Labels.Second }, new Label[] { Labels.Second });
                    }
                    finally
                    {
                        Db.shutdown();
                    }
                }
            }).build();

            _life.add(clusterManager);
            _life.start();
            _cluster = clusterManager.Cluster;
            _cluster.await(allSeesAllAsAvailable());
            _cluster.await(allAvailabilityGuardsReleased());
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testMasterElectionAfterMasterRecoversInSlaveOnlyCluster() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestMasterElectionAfterMasterRecoversInSlaveOnlyCluster()
        {
            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
            assertThat(cluster.GetServerId(cluster.Master), equalTo(new InstanceId(3)));
            HighlyAvailableGraphDatabase master = cluster.Master;

            System.Threading.CountdownEvent masterFailedLatch = CreateMasterFailLatch(cluster);
            ClusterManager.RepairKit        repairKit         = cluster.Fail(master);
            try
            {
                assertTrue(masterFailedLatch.await(60, TimeUnit.SECONDS));
            }
            finally
            {
                repairKit.Repair();
            }

            cluster.Await(allSeesAllAsAvailable());
            long nodeId = CreateNodeWithPropertyOn(cluster.AnySlave, PROPERTY, VALUE);

            using (Transaction ignore = master.BeginTx())
            {
                assertThat(master.GetNodeById(nodeId).getProperty(PROPERTY), equalTo(VALUE));
            }
        }
Exemplo n.º 6
0
        private System.Threading.CountdownEvent CreateMasterFailLatch(ClusterManager.ManagedCluster cluster)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch failedLatch = new java.util.concurrent.CountDownLatch(2);
            System.Threading.CountdownEvent failedLatch = new System.Threading.CountdownEvent(2);
            foreach (HighlyAvailableGraphDatabase db in cluster.AllMembers)
            {
                if (!Db.Master)
                {
                    Db.DependencyResolver.resolveDependency(typeof(ClusterClient)).addHeartbeatListener(new HeartbeatListenerAnonymousInnerClass(this, failedLatch));
                }
            }
            return(failedLatch);
        }