Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void bootstrapCluster() throws Exception
        private void BootstrapCluster()
        {
            string instance1            = "cluster://localhost:5001";
            string instance2            = "cluster://localhost:5002";
            string instance3            = "cluster://localhost:5003";
            ClusterConfiguration config = new ClusterConfiguration("default", NullLogProvider.Instance, instance1, instance2, instance3);

            ClusterState state = new ClusterState(new IList <ClusterInstance> {
                newClusterInstance(new InstanceId(1), new URI(instance1), new Monitors(), config, 10, NullLogProvider.Instance), newClusterInstance(new InstanceId(2), new URI(instance2), new Monitors(), config, 10, NullLogProvider.Instance), newClusterInstance(new InstanceId(3), new URI(instance3), new Monitors(), config, 10, NullLogProvider.Instance)
            }, emptySet());

            state = state.PerformAction(new MessageDeliveryAction(Message.to(ClusterMessage.create, new URI(instance3), "defaultcluster").setHeader(Message.HEADER_CONVERSATION_ID, "-1").setHeader(Message.HEADER_FROM, instance3)));
            state = state.PerformAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI(instance2), new object[]
            {
                "defaultcluster", new URI[] { new URI(instance3) }
            }).setHeader(Message.HEADER_CONVERSATION_ID, "-1").setHeader(Message.HEADER_FROM, instance2)));
            state = state.PerformAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI(instance1), new object[]
            {
                "defaultcluster", new URI[] { new URI(instance3) }
            }).setHeader(Message.HEADER_CONVERSATION_ID, "-1").setHeader(Message.HEADER_FROM, instance1)));

            state.AddPendingActions(new InstanceCrashedAction(instance3));

            _unexploredKnownStates.AddLast(state);

            _db.newState(state);
        }
Пример #2
0
        private void ExploreUnexploredStates()
        {
            while (_unexploredKnownStates.Count > 0)
            {
                ClusterState state = _unexploredKnownStates.RemoveFirst();

                IEnumerator <Pair <ClusterAction, ClusterState> > newStates = state.Transitions();
                while (newStates.MoveNext())
                {
                    Pair <ClusterAction, ClusterState> next = newStates.Current;
                    Console.WriteLine(_db.numberOfKnownStates() + " (" + _unexploredKnownStates.Count + ")");

                    ClusterState nextState = next.Other();
                    if (!_db.isKnownState(nextState))
                    {
                        _db.newStateTransition(state, next);
                        _unexploredKnownStates.AddLast(nextState);

                        if (nextState.DeadEnd)
                        {
                            Console.WriteLine("DEAD END: " + nextState.ToString() + " (" + _db.id(nextState) + ")");
                        }
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Managing timeouts is trickier than putting all of them in a long list, like regular message delivery.
        ///  Timeouts are ordered and can be cancelled, so they need special treatment. Hence a separate method for
        ///  managing timeouts triggering.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.helpers.collection.Pair<ClusterAction, ClusterState> performNextTimeoutFrom(ClusterInstance instance) throws Exception
        private Pair <ClusterAction, ClusterState> PerformNextTimeoutFrom(ClusterInstance instance)
        {
            ClusterState  newState      = Snapshot();
            ClusterAction clusterAction = newState.Instance(instance.Uri().toASCIIString()).popTimeout();

            clusterAction.Perform(newState);

            return(Pair.of(clusterAction, newState));
        }
Пример #4
0
        public virtual Node NewState(ClusterState state)
        {
            using (Transaction tx = _gds.beginTx())
            {
                Node node = _gds.createNode(label("State"));
                node.SetProperty("description", state.ToString());
                tx.Success();

                _stateNodes[state] = node;
                return(node);
            }
        }
Пример #5
0
        public virtual void NewStateTransition(ClusterState originalState, Pair <ClusterAction, ClusterState> transition)
        {
            using (Transaction tx = _gds.beginTx())
            {
                Node stateNode = _stateNodes[originalState];

                Node subStateNode = NewState(transition.Other());

                Relationship msg = stateNode.CreateRelationshipTo(subStateNode, RelationshipType.withName("MESSAGE"));
                msg.SetProperty("description", transition.First().ToString());
                tx.Success();
            }
        }
Пример #6
0
        /// <summary>
        /// Clone the state and perform the action with the provided index. Returns the new state and the action. </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: ClusterState performAction(ClusterAction action) throws Exception
        internal virtual ClusterState PerformAction(ClusterAction action)
        {
            ClusterState newState = Snapshot();

            // Remove the action from the list of things that can happen in the snapshot
            newState._pendingActions.remove(action);

            // Perform the action on the cloned state
            IEnumerable <ClusterAction> newActions = action.Perform(newState);

            // Include any outcome actions into the new state snapshot
            newState._pendingActions.addAll(Iterables.asCollection(newActions));

            return(newState);
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void aClusterSnapshotShouldEqualItsOrigin() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AClusterSnapshotShouldEqualItsOrigin()
        {
            // Given
            ClusterConfiguration config = new ClusterConfiguration("default", NullLogProvider.Instance, "cluster://localhost:5001", "cluster://localhost:5002", "cluster://localhost:5003");

            ClusterState state = new ClusterState(new IList <ClusterInstance> {
                newClusterInstance(new InstanceId(1), new URI("cluster://localhost:5001"), new Monitors(), config, 10, NullLogProvider.Instance), newClusterInstance(new InstanceId(2), new URI("cluster://localhost:5002"), new Monitors(), config, 10, NullLogProvider.Instance), newClusterInstance(new InstanceId(3), new URI("cluster://localhost:5003"), new Monitors(), config, 10, NullLogProvider.Instance)
            }, emptySet());

            // When
            ClusterState snapshot = state.Snapshot();

            // Then
            assertEquals(state, snapshot);
            assertEquals(state.GetHashCode(), snapshot.GetHashCode());
        }
Пример #8
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }

            ClusterState that = ( ClusterState )o;

//JAVA TO C# CONVERTER WARNING: LINQ 'SequenceEqual' is not always identical to Java AbstractList 'equals':
//ORIGINAL LINE: return instances.equals(that.instances) && pendingActions.equals(that.pendingActions);
            return(_instances.SequenceEqual(that._instances) && _pendingActions.SetEquals(that._pendingActions));
        }
Пример #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void twoStatesWithSameSetupAndPendingMessagesShouldBeEqual() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TwoStatesWithSameSetupAndPendingMessagesShouldBeEqual()
        {
            // Given
            ClusterConfiguration config = new ClusterConfiguration("default", NullLogProvider.Instance, "cluster://localhost:5001", "cluster://localhost:5002", "cluster://localhost:5003");

            ClusterState state = new ClusterState(new IList <ClusterInstance> {
                newClusterInstance(new InstanceId(1), new URI("cluster://localhost:5001"), new Monitors(), config, 10, NullLogProvider.Instance), newClusterInstance(new InstanceId(2), new URI("cluster://localhost:5002"), new Monitors(), config, 10, NullLogProvider.Instance), newClusterInstance(new InstanceId(3), new URI("cluster://localhost:5003"), new Monitors(), config, 10, NullLogProvider.Instance)
            }, emptySet());

            // When
            ClusterState firstState = state.PerformAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI("cluster://localhost:5002"), new object[]
            {
                "defaultcluster", new URI[] { new URI("cluster://localhost:5003") }
            }).setHeader(Message.HEADER_CONVERSATION_ID, "-1").setHeader(Message.HEADER_FROM, "cluster://localhost:5002")));
            ClusterState secondState = state.PerformAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI("cluster://localhost:5002"), new object[]
            {
                "defaultcluster", new URI[] { new URI("cluster://localhost:5003") }
            }).setHeader(Message.HEADER_CONVERSATION_ID, "-1").setHeader(Message.HEADER_FROM, "cluster://localhost:5002")));

            // Then
            assertEquals(firstState, secondState);
            assertEquals(firstState.GetHashCode(), secondState.GetHashCode());
        }
Пример #10
0
 public virtual long Id(ClusterState nextState)
 {
     return(_stateNodes[nextState].Id);
 }
Пример #11
0
 public virtual bool IsKnownState(ClusterState state)
 {
     return(_stateNodes.ContainsKey(state));
 }
Пример #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Iterable<ClusterAction> perform(ClusterState state) throws Exception
        public override IEnumerable <ClusterAction> Perform(ClusterState state)
        {
            state.Instance(_instanceUri).crash();
            return(Iterables.empty());
        }