Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void leaderShouldStepDownWhenFollowersAreGone() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LeaderShouldStepDownWhenFollowersAreGone()
        {
            // when
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster = ClusterRule.startCluster();

            //Do some work to make sure the cluster is operating normally.
            CoreClusterMember leader = cluster.CoreTx((db, tx) =>
            {
                Node node = Db.createNode(Label.label("bam"));
                node.setProperty("bam", "bam");
                tx.success();
            });

            ThrowingSupplier <IList <CoreClusterMember>, Exception> followers = () => cluster.CoreMembers().Where(m => m.raft().currentRole() != Role.LEADER).ToList();

            assertEventually("All followers visible", followers, Matchers.hasSize(7), 2, TimeUnit.MINUTES);

            //when
            //shutdown 4 servers, leaving 4 remaining and therefore not a quorum.
            followers.Get().subList(0, 4).forEach(CoreClusterMember.shutdown);

            //then
            assertEventually("Leader should have stepped down.", () => leader.Raft().Leader, Matchers.@is(false), 2, TimeUnit.MINUTES);
        }
Пример #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private T getOrCreatePart(Offset key, org.neo4j.function.ThrowingSupplier<T,java.io.IOException> factory) throws java.io.UncheckedIOException
        private T GetOrCreatePart(Offset key, ThrowingSupplier <T, IOException> factory)
        {
            T existing = Cache[key];

            if (existing != default(T))
            {
                return(existing);
            }

            // Instantiate from factory. Do this under lock so that we coordinate with any concurrent call to close.
            // Concurrent calls to instantiating parts won't contend with each other since there's only
            // a single writer at a time anyway.
            InstantiateCloseLock.@lock();
            try
            {
                AssertOpen();
                return(Cache.computeIfAbsent(key, k =>
                {
                    try
                    {
                        return factory.Get();
                    }
                    catch (IOException e)
                    {
                        throw new UncheckedIOException(e);
                    }
                }));
            }
            finally
            {
                InstantiateCloseLock.unlock();
            }
        }
Пример #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private ProgressiveState<String> stateWithLookup(org.neo4j.function.ThrowingSupplier<bool, java.io.IOException> valueSupplier) throws java.io.IOException
        private ProgressiveState <string> StateWithLookup(ThrowingSupplier <bool, IOException> valueSupplier)
        {
            ProgressiveState <string> state = mock(typeof(ProgressiveState));

            when(state.lookup(any(), any())).thenAnswer(invocation =>
            {
                bool wasFound = valueSupplier.Get();
                invocation.getArgument <ValueLookup <string> >(1).value(null);
                return(wasFound);
            });
            return(state);
        }
Пример #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static <EXCEPTION extends Exception> boolean tryAwaitEx(ThrowingSupplier<bool,EXCEPTION> condition, long timeout, java.util.concurrent.TimeUnit timeoutUnit, long pollInterval, java.util.concurrent.TimeUnit pollUnit, java.time.Clock clock) throws EXCEPTION
        public static bool TryAwaitEx <EXCEPTION>(ThrowingSupplier <bool, EXCEPTION> condition, long timeout, TimeUnit timeoutUnit, long pollInterval, TimeUnit pollUnit, Clock clock) where EXCEPTION : Exception
        {
            long deadlineMillis    = clock.millis() + timeoutUnit.toMillis(timeout);
            long pollIntervalNanos = pollUnit.toNanos(pollInterval);

            do
            {
                if (condition.Get())
                {
                    return(true);
                }
                LockSupport.parkNanos(pollIntervalNanos);
            } while (clock.millis() < deadlineMillis);
            return(false);
        }