Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testFailure() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestFailure()
        {
            ScriptableNetworkFailureLatencyStrategy networkLatency = new ScriptableNetworkFailureLatencyStrategy();
            NetworkMock network = new NetworkMock(NullLogService.Instance, new Monitors(), 50, new MultipleFailureLatencyStrategy(networkLatency), new MessageTimeoutStrategy(new FixedTimeoutStrategy(1000)));

            IList <TestProtocolServer> nodes = new List <TestProtocolServer>();

            TestProtocolServer server = network.AddServer(1, URI.create("cluster://server1"));

            server.NewClient(typeof(Cluster)).create("default");
            network.TickUntilDone();
            nodes.Add(server);

            for (int i = 1; i < 3; i++)
            {
                TestProtocolServer protocolServer = network.AddServer(i + 1, new URI("cluster://server" + (i + 1)));
                protocolServer.NewClient(typeof(Cluster)).join("default", new URI("cluster://server1"));
                network.Tick(10);
                nodes.Add(protocolServer);
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcast atomicBroadcast = nodes.get(0).newClient(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcast.class);
            AtomicBroadcast     atomicBroadcast     = nodes[0].NewClient(typeof(AtomicBroadcast));
            ObjectStreamFactory objectStreamFactory = new ObjectStreamFactory();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer serializer = new org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer(objectStreamFactory, objectStreamFactory);
            AtomicBroadcastSerializer serializer = new AtomicBroadcastSerializer(objectStreamFactory, objectStreamFactory);

            atomicBroadcast.Broadcast(serializer.Broadcast(new DaPayload()));

            networkLatency.NodeIsDown("cluster://server2");
            networkLatency.NodeIsDown("cluster://server3");

            atomicBroadcast.Broadcast(serializer.Broadcast(new DaPayload()));
            network.Tick(100);
            networkLatency.NodeIsUp("cluster://server3");
            network.Tick(1000);

            foreach (TestProtocolServer node in nodes)
            {
                node.NewClient(typeof(Cluster)).leave();
                network.Tick(10);
            }
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void testCluster(int[] serverIds, org.neo4j.cluster.VerifyInstanceConfiguration[] finalConfig, org.neo4j.cluster.NetworkMock mock, ClusterTestScript script) throws java.net.URISyntaxException
        protected internal virtual void TestCluster(int[] serverIds, VerifyInstanceConfiguration[] finalConfig, NetworkMock mock, ClusterTestScript script)
        {
            this.Script = script;

            Network = mock;
            Servers.Clear();
            Out.Clear();
            In.Clear();

            for (int i = 0; i < serverIds.Length; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.net.URI uri = new java.net.URI("server" + (i + 1));
                URI uri = new URI("server" + (i + 1));
                Members[serverIds[i]] = uri;
                TestProtocolServer server = Network.addServer(serverIds[i], uri);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Cluster cluster = server.newClient(Cluster.class);
                Cluster cluster = server.NewClient(typeof(Cluster));
                ClusterStateListener(uri, cluster);

                server.NewClient(typeof(Heartbeat)).addHeartbeatListener(new HeartbeatListenerAnonymousInnerClass(this, uri, server));
                server.NewClient(typeof(AtomicBroadcast)).addAtomicBroadcastListener(new AtomicBroadcastListenerAnonymousInnerClass(this, uri));

                Servers.Add(server);
                Out.Add(cluster);
            }

            // Run test
            for (int i = 0; i < script.Rounds(); i++)
            {
                Logger.Logger.fine("Round " + i + ", time:" + Network.Time);

                script.Tick(Network.Time.Value);

                Network.tick();
            }

            // Let messages settle
            Network.tick(100);
            if (finalConfig == null)
            {
                VerifyConfigurations("final config");
            }
            else
            {
                VerifyConfigurations(finalConfig);
            }

            Logger.Logger.fine("All nodes leave");

            // All leave
            foreach (Cluster cluster in new List <>(In))
            {
                Logger.Logger.fine("Leaving:" + cluster);
                cluster.Leave();
                In.Remove(cluster);
                Network.tick(400);
            }

            if (finalConfig != null)
            {
                VerifyConfigurations(finalConfig);
            }
            else
            {
                VerifyConfigurations("test over");
            }
        }