Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBootstrapWhenBootstrappable() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBootstrapWhenBootstrappable()
        {
            // given
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            IDictionary <MemberId, CoreServerInfo> members = IntStream.range(0, _minCoreHosts).mapToObj(i => Pair.of(new MemberId(System.Guid.randomUUID()), TestTopology.addressesForCore(i, false))).collect(Collectors.toMap(Pair::first, Pair::other));

            CoreTopology bootstrappableTopology = new CoreTopology(null, true, members);

            CoreTopologyService topologyService = mock(typeof(CoreTopologyService));

            when(topologyService.LocalCoreServers()).thenReturn(bootstrappableTopology);
            when(topologyService.SetClusterId(any(), eq("default"))).thenReturn(true);
            CoreSnapshot snapshot = mock(typeof(CoreSnapshot));

            when(_coreBootstrapper.bootstrap(any())).thenReturn(snapshot);

            ClusterBinder binder = ClusterBinder(new StubSimpleStorage <ClusterId>(this), topologyService);

            // when
            BoundState boundState = binder.BindToCluster();

            // then
            verify(_coreBootstrapper).bootstrap(any());
            Optional <ClusterId> clusterId = binder.Get();

            assertTrue(clusterId.Present);
            verify(topologyService).setClusterId(clusterId.get(), "default");
            assertTrue(boundState.Snapshot().Present);
            assertEquals(boundState.Snapshot().get(), snapshot);
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailToPublishMismatchingStoredClusterId() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailToPublishMismatchingStoredClusterId()
        {
            // given
            ClusterId previouslyBoundClusterId = new ClusterId(System.Guid.randomUUID());

            CoreTopologyService topologyService = mock(typeof(CoreTopologyService));

            when(topologyService.SetClusterId(previouslyBoundClusterId, "default")).thenReturn(false);

            StubSimpleStorage <ClusterId> clusterIdStorage = new StubSimpleStorage <ClusterId>(this);

            clusterIdStorage.WriteState(previouslyBoundClusterId);

            ClusterBinder binder = ClusterBinder(clusterIdStorage, topologyService);

            // when
            try
            {
                binder.BindToCluster();
                fail("Should have thrown exception");
            }
            catch (BindingException)
            {
                // expected
            }
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPublishStoredClusterIdIfPreviouslyBound() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPublishStoredClusterIdIfPreviouslyBound()
        {
            // given
            ClusterId previouslyBoundClusterId = new ClusterId(System.Guid.randomUUID());

            CoreTopologyService topologyService = mock(typeof(CoreTopologyService));

            when(topologyService.SetClusterId(previouslyBoundClusterId, "default")).thenReturn(true);

            StubSimpleStorage <ClusterId> clusterIdStorage = new StubSimpleStorage <ClusterId>(this);

            clusterIdStorage.WriteState(previouslyBoundClusterId);

            ClusterBinder binder = ClusterBinder(clusterIdStorage, topologyService);

            // when
            binder.BindToCluster();

            // then
            verify(topologyService).setClusterId(previouslyBoundClusterId, "default");
            Optional <ClusterId> clusterId = binder.Get();

            assertTrue(clusterId.Present);
            assertEquals(previouslyBoundClusterId, clusterId.get());
        }
Exemple #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = java.util.concurrent.TimeoutException.class) public void shouldTimeoutIfPublishContinuallyFailsWithTransientErrors() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTimeoutIfPublishContinuallyFailsWithTransientErrors()
        {
            // given
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            IDictionary <MemberId, CoreServerInfo> members = IntStream.range(0, _minCoreHosts).mapToObj(i => Pair.of(new MemberId(System.Guid.randomUUID()), TestTopology.addressesForCore(i, false))).collect(Collectors.toMap(Pair::first, Pair::other));

            CoreTopology        bootstrappableTopology = new CoreTopology(null, true, members);
            CoreTopologyService topologyService        = mock(typeof(CoreTopologyService));

            when(topologyService.SetClusterId(any(), anyString())).thenThrow(typeof(OperationTimeoutException));                   // Causes a retry
            when(topologyService.LocalCoreServers()).thenReturn(bootstrappableTopology);

            ClusterBinder binder = ClusterBinder(new StubSimpleStorage <ClusterId>(this), topologyService);

            // when
            binder.BindToCluster();
        }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBindToClusterIdPublishedByAnotherMember() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBindToClusterIdPublishedByAnotherMember()
        {
            // given
            ClusterId    publishedClusterId = new ClusterId(System.Guid.randomUUID());
            CoreTopology unboundTopology    = new CoreTopology(null, false, emptyMap());
            CoreTopology boundTopology      = new CoreTopology(publishedClusterId, false, emptyMap());

            CoreTopologyService topologyService = mock(typeof(CoreTopologyService));

            when(topologyService.LocalCoreServers()).thenReturn(unboundTopology).thenReturn(boundTopology);

            ClusterBinder binder = ClusterBinder(new StubSimpleStorage <ClusterId>(this), topologyService);

            // when
            binder.BindToCluster();

            // then
            Optional <ClusterId> clusterId = binder.Get();

            assertTrue(clusterId.Present);
            assertEquals(publishedClusterId, clusterId.get());
            verify(topologyService, atLeast(2)).localCoreServers();
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTimeoutWhenNotBootstrappableAndNobodyElsePublishesClusterId() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTimeoutWhenNotBootstrappableAndNobodyElsePublishesClusterId()
        {
            // given
            CoreTopology        unboundTopology = new CoreTopology(null, false, emptyMap());
            CoreTopologyService topologyService = mock(typeof(CoreTopologyService));

            when(topologyService.LocalCoreServers()).thenReturn(unboundTopology);

            ClusterBinder binder = ClusterBinder(new StubSimpleStorage <ClusterId>(this), topologyService);

            try
            {
                // when
                binder.BindToCluster();
                fail("Should have timed out");
            }
            catch (TimeoutException)
            {
                // expected
            }

            // then
            verify(topologyService, atLeast(2)).localCoreServers();
        }