Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void before() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Before()
        {
            _directory = TestDirectory.directory("temp");
            _life      = new LifeSupport();
            _life.start();               // So that the clients get started as they are added
            _clients = new ClusterClient[2];
            for (int i = 1; i <= _clients.Length; i++)
            {
                IDictionary <string, string> config = stringMap();
                config[cluster_server.name()] = ":" + (5000 + i);
                config[server_id.name()]      = "" + i;
                config[initial_hosts.name()]  = ":5001";

                LifeSupport         moduleLife          = new LifeSupport();
                ClusterClientModule clusterClientModule = new ClusterClientModule(moduleLife, new Dependencies(), new Monitors(), Config.defaults(config), NullLogService.Instance, new ServerIdElectionCredentialsProvider());

                ClusterClient client = clusterClientModule.ClusterClient;
                System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1);
                client.AddClusterListener(new ClusterListener_AdapterAnonymousInnerClass(this, client, latch));
                _life.add(moduleLife);
                _clients[i - 1] = client;
                assertTrue("Didn't join the cluster", latch.await(20, SECONDS));
            }
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPullUpdatesOnStartupNoMatterWhat() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPullUpdatesOnStartupNoMatterWhat()
        {
            HighlyAvailableGraphDatabase slave  = null;
            HighlyAvailableGraphDatabase master = null;

            try
            {
                File testRootDir       = ClusterRule.cleanDirectory("shouldPullUpdatesOnStartupNoMatterWhat");
                File masterDir         = ClusterRule.TestDirectory.databaseDir("master");
                int  masterClusterPort = PortAuthority.allocatePort();
                master = ( HighlyAvailableGraphDatabase )(new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(masterDir).setConfig(ClusterSettings.server_id, "1").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + masterClusterPort).setConfig(ClusterSettings.initial_hosts, "localhost:" + masterClusterPort).setConfig(HaSettings.ha_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase();

                // Copy the store, then shutdown, so update pulling later makes sense
                File slaveDir = ClusterRule.TestDirectory.databaseDir("slave");
                slave = ( HighlyAvailableGraphDatabase )(new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(slaveDir).setConfig(ClusterSettings.server_id, "2").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(ClusterSettings.initial_hosts, "localhost:" + masterClusterPort).setConfig(HaSettings.ha_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase();

                // Required to block until the slave has left for sure
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch slaveLeftLatch = new java.util.concurrent.CountDownLatch(1);
                System.Threading.CountdownEvent slaveLeftLatch = new System.Threading.CountdownEvent(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.client.ClusterClient masterClusterClient = master.getDependencyResolver().resolveDependency(org.neo4j.cluster.client.ClusterClient.class);
                ClusterClient masterClusterClient = master.DependencyResolver.resolveDependency(typeof(ClusterClient));
                masterClusterClient.AddClusterListener(new ClusterListener_AdapterAnonymousInnerClass(this, slaveLeftLatch, masterClusterClient));

                master.DependencyResolver.resolveDependency(typeof(LogService)).getInternalLog(this.GetType()).info("SHUTTING DOWN SLAVE");
                slave.Shutdown();
                slave = null;

                // Make sure that the slave has left, because shutdown() may return before the master knows
                assertTrue("Timeout waiting for slave to leave", slaveLeftLatch.await(60, TimeUnit.SECONDS));

                long nodeId;
                using (Transaction tx = master.BeginTx())
                {
                    Node node = master.CreateNode();
                    node.SetProperty("from", "master");
                    nodeId = node.Id;
                    tx.Success();
                }

                // Store is already in place, should pull updates
                slave = ( HighlyAvailableGraphDatabase )(new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(slaveDir).setConfig(ClusterSettings.server_id, "2").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(ClusterSettings.initial_hosts, "localhost:" + masterClusterPort).setConfig(HaSettings.ha_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(HaSettings.pull_interval, "0").setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase();

                slave.BeginTx().close();                         // Make sure switch to slave completes and so does the update pulling on startup

                using (Transaction tx = slave.BeginTx())
                {
                    assertEquals("master", slave.GetNodeById(nodeId).getProperty("from"));
                    tx.Success();
                }
            }
            finally
            {
                if (slave != null)
                {
                    slave.Shutdown();
                }
                if (master != null)
                {
                    master.Shutdown();
                }
            }
        }