Leaders { public static <T> List<T> createProxyAndLocalList( T localObject, Set<String> remoteUris, Supplier<RemotingClientConfig> remotingClientConfig, Optional<TrustContext> trustContext, Class<T> clazz, UserAgent userAgent) { List<T> remotes = remoteUris.stream() .map(uri -> AtlasDbHttpClients.createProxy( trustContext, uri, clazz, AuxiliaryRemotingParameters.builder() .userAgent(userAgent) .shouldLimitPayload(false) .shouldRetry(true) .shouldUseExtendedTimeout(false) .remotingClientConfig(remotingClientConfig) .build())) .collect(Collectors.toList()); return ImmutableList.copyOf(Iterables.concat( remotes, ImmutableList.of(localObject))); } private  Leaders(); static LocalPaxosServices createAndRegisterLocalServices(MetricsManager metricsManager,
            Consumer<Object> env,
            LeaderConfig config,
            UserAgent userAgent); static LocalPaxosServices createInstrumentedLocalServices(MetricsManager metricsManager,
            LeaderConfig config,
            UserAgent userAgent); static LocalPaxosServices createInstrumentedLocalServices(
            MetricsManager metricsManager,
            LeaderConfig config,
            RemotePaxosServerSpec remotePaxosServerSpec,
            Supplier<RemotingClientConfig> remotingClientConfig,
            UserAgent userAgent,
            LeadershipObserver leadershipObserver); static List<T> createProxyAndLocalList(
            T localObject,
            Set<String> remoteUris,
            Supplier<RemotingClientConfig> remotingClientConfig,
            Optional<TrustContext> trustContext,
            Class<T> clazz,
            UserAgent userAgent); static List<LeaderPingerContext<PingableLeader>> generatePingables(
            Collection<String> remoteEndpoints,
            Supplier<RemotingClientConfig> remotingClientConfig,
            Optional<TrustContext> trustContext,
            UserAgent userAgent);  }
@Test public void canCreateProxyAndLocalListOfPaxosLearners() { PaxosLearner localLearner = mock(PaxosLearner.class); Optional<PaxosValue> presentPaxosValue = Optional.of(mock(PaxosValue.class)); when(localLearner.getGreatestLearnedValue()).thenReturn(presentPaxosValue); List<PaxosLearner> paxosLearners = Leaders.createProxyAndLocalList( localLearner, REMOTE_SERVICE_ADDRESSES, REMOTING_CLIENT_CONFIG, Optional.of(TRUST_CONTEXT), PaxosLearner.class, AtlasDbRemotingConstants.DEFAULT_USER_AGENT); MatcherAssert.assertThat(paxosLearners.size(), is(REMOTE_SERVICE_ADDRESSES.size() + 1)); paxosLearners.forEach(object -> MatcherAssert.assertThat(object, not(nullValue()))); MatcherAssert.assertThat(Iterables.getLast(paxosLearners).getGreatestLearnedValue(), is(presentPaxosValue)); verify(localLearner).getGreatestLearnedValue(); verifyNoMoreInteractions(localLearner); }
@Test public void canCreateProxyAndLocalListOfPaxosAcceptors() { PaxosAcceptor localAcceptor = mock(PaxosAcceptor.class); when(localAcceptor.getLatestSequencePreparedOrAccepted()).thenReturn(1L); List<PaxosAcceptor> paxosAcceptors = Leaders.createProxyAndLocalList( localAcceptor, REMOTE_SERVICE_ADDRESSES, REMOTING_CLIENT_CONFIG, Optional.of(TRUST_CONTEXT), PaxosAcceptor.class, AtlasDbRemotingConstants.DEFAULT_USER_AGENT); MatcherAssert.assertThat(paxosAcceptors.size(), is(REMOTE_SERVICE_ADDRESSES.size() + 1)); paxosAcceptors.forEach(object -> MatcherAssert.assertThat(object, not(nullValue()))); MatcherAssert.assertThat(Iterables.getLast(paxosAcceptors).getLatestSequencePreparedOrAccepted(), is(1L)); verify(localAcceptor).getLatestSequencePreparedOrAccepted(); verifyNoMoreInteractions(localAcceptor); }
@Test public void createProxyAndLocalListCreatesSingletonListIfNoRemoteAddressesProvided() { PaxosAcceptor localAcceptor = mock(PaxosAcceptor.class); when(localAcceptor.getLatestSequencePreparedOrAccepted()).thenReturn(1L); List<PaxosAcceptor> paxosAcceptors = Leaders.createProxyAndLocalList( localAcceptor, ImmutableSet.of(), REMOTING_CLIENT_CONFIG, Optional.of(TRUST_CONTEXT), PaxosAcceptor.class, AtlasDbRemotingConstants.DEFAULT_USER_AGENT); MatcherAssert.assertThat(paxosAcceptors.size(), is(1)); MatcherAssert.assertThat(Iterables.getLast(paxosAcceptors).getLatestSequencePreparedOrAccepted(), is(1L)); verify(localAcceptor).getLatestSequencePreparedOrAccepted(); verifyNoMoreInteractions(localAcceptor); }
@Test(expected = NullPointerException.class) public void createProxyAndLocalListThrowsIfNullClassProvided() { PaxosAcceptor localAcceptor = mock(PaxosAcceptor.class); Leaders.createProxyAndLocalList( localAcceptor, REMOTE_SERVICE_ADDRESSES, REMOTING_CLIENT_CONFIG, Optional.of(TRUST_CONTEXT), null, AtlasDbRemotingConstants.DEFAULT_USER_AGENT); }