Search in sources :

Example 1 with LoadBalancingResult

use of org.neo4j.causalclustering.load_balancing.LoadBalancingResult in project neo4j by neo4j.

the class ResultFormatV1Test method shouldSerializeToAndFromRecordFormat.

@Test
public void shouldSerializeToAndFromRecordFormat() throws Exception {
    // given
    List<Endpoint> writers = asList(Endpoint.write(new AdvertisedSocketAddress("write", 1)), Endpoint.write(new AdvertisedSocketAddress("write", 2)), Endpoint.write(new AdvertisedSocketAddress("write", 3)));
    List<Endpoint> readers = asList(Endpoint.read(new AdvertisedSocketAddress("read", 4)), Endpoint.read(new AdvertisedSocketAddress("read", 5)), Endpoint.read(new AdvertisedSocketAddress("read", 6)), Endpoint.read(new AdvertisedSocketAddress("read", 7)));
    List<Endpoint> routers = singletonList(Endpoint.route(new AdvertisedSocketAddress("route", 8)));
    long ttlSeconds = 5;
    LoadBalancingResult original = new LoadBalancingResult(routers, writers, readers, ttlSeconds * 1000);
    // when
    Object[] record = ResultFormatV1.build(original);
    // then
    LoadBalancingResult parsed = ResultFormatV1.parse(record);
    assertEquals(original, parsed);
}
Also used : LoadBalancingResult(org.neo4j.causalclustering.load_balancing.LoadBalancingResult) Endpoint(org.neo4j.causalclustering.load_balancing.Endpoint) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) Test(org.junit.Test)

Example 2 with LoadBalancingResult

use of org.neo4j.causalclustering.load_balancing.LoadBalancingResult in project neo4j by neo4j.

the class ServerPoliciesPlugin method run.

@Override
public Result run(Map<String, String> context) {
    CoreTopology coreTopology = topologyService.coreServers();
    ReadReplicaTopology rrTopology = topologyService.readReplicas();
    return new LoadBalancingResult(routeEndpoints(coreTopology), writeEndpoints(coreTopology), readEndpoints(coreTopology, rrTopology, policies.selectFor(context)), timeToLive);
}
Also used : LoadBalancingResult(org.neo4j.causalclustering.load_balancing.LoadBalancingResult) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology)

Example 3 with LoadBalancingResult

use of org.neo4j.causalclustering.load_balancing.LoadBalancingResult in project neo4j by neo4j.

the class ServerShufflingProcessorTest method shouldShuffleServers.

@Test
public void shouldShuffleServers() throws Exception {
    // given
    LoadBalancingProcessor delegate = mock(LoadBalancingPlugin.class);
    List<Endpoint> routers = asList(Endpoint.route(new AdvertisedSocketAddress("route", 1)), Endpoint.route(new AdvertisedSocketAddress("route", 2)));
    List<Endpoint> writers = asList(Endpoint.write(new AdvertisedSocketAddress("write", 3)), Endpoint.write(new AdvertisedSocketAddress("write", 4)), Endpoint.write(new AdvertisedSocketAddress("write", 5)));
    List<Endpoint> readers = asList(Endpoint.read(new AdvertisedSocketAddress("read", 6)), Endpoint.read(new AdvertisedSocketAddress("read", 7)), Endpoint.read(new AdvertisedSocketAddress("read", 8)), Endpoint.read(new AdvertisedSocketAddress("read", 9)));
    long ttl = 1000;
    LoadBalancingProcessor.Result result = new LoadBalancingResult(new ArrayList<>(routers), new ArrayList<>(writers), new ArrayList<>(readers), ttl);
    when(delegate.run(any())).thenReturn(result);
    ServerShufflingProcessor plugin = new ServerShufflingProcessor(delegate);
    boolean completeShuffle = false;
    for (// we try many times to make false negatives extremely unlikely
    int i = 0; // we try many times to make false negatives extremely unlikely
    i < 1000; // we try many times to make false negatives extremely unlikely
    i++) {
        // when
        LoadBalancingProcessor.Result shuffledResult = plugin.run(Collections.emptyMap());
        // then: should still contain the same endpoints
        assertThat(shuffledResult.routeEndpoints(), containsInAnyOrder(routers.toArray()));
        assertThat(shuffledResult.writeEndpoints(), containsInAnyOrder(writers.toArray()));
        assertThat(shuffledResult.readEndpoints(), containsInAnyOrder(readers.toArray()));
        assertEquals(shuffledResult.getTimeToLiveMillis(), ttl);
        // but possibly in a different order
        boolean readersEqual = shuffledResult.readEndpoints().equals(readers);
        boolean writersEqual = shuffledResult.writeEndpoints().equals(writers);
        boolean routersEqual = shuffledResult.routeEndpoints().equals(routers);
        if (!readersEqual && !writersEqual && !routersEqual) {
            // we don't stop until it is completely different
            completeShuffle = true;
            break;
        }
    }
    assertTrue(completeShuffle);
}
Also used : LoadBalancingResult(org.neo4j.causalclustering.load_balancing.LoadBalancingResult) Endpoint(org.neo4j.causalclustering.load_balancing.Endpoint) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) LoadBalancingProcessor(org.neo4j.causalclustering.load_balancing.LoadBalancingProcessor) Endpoint(org.neo4j.causalclustering.load_balancing.Endpoint) Test(org.junit.Test)

Example 4 with LoadBalancingResult

use of org.neo4j.causalclustering.load_balancing.LoadBalancingResult in project neo4j by neo4j.

the class ResultFormatV1Test method shouldSerializeToAndFromRecordFormatWithNoEntries.

@Test
public void shouldSerializeToAndFromRecordFormatWithNoEntries() throws Exception {
    // given
    List<Endpoint> writers = emptyList();
    List<Endpoint> readers = emptyList();
    List<Endpoint> routers = emptyList();
    long ttlSeconds = 0;
    LoadBalancingResult original = new LoadBalancingResult(routers, writers, readers, ttlSeconds * 1000);
    // when
    Object[] record = ResultFormatV1.build(original);
    // then
    LoadBalancingResult parsed = ResultFormatV1.parse(record);
    assertEquals(original, parsed);
}
Also used : LoadBalancingResult(org.neo4j.causalclustering.load_balancing.LoadBalancingResult) Endpoint(org.neo4j.causalclustering.load_balancing.Endpoint) Test(org.junit.Test)

Aggregations

LoadBalancingResult (org.neo4j.causalclustering.load_balancing.LoadBalancingResult)4 Test (org.junit.Test)3 Endpoint (org.neo4j.causalclustering.load_balancing.Endpoint)3 AdvertisedSocketAddress (org.neo4j.helpers.AdvertisedSocketAddress)2 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)1 ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)1 LoadBalancingProcessor (org.neo4j.causalclustering.load_balancing.LoadBalancingProcessor)1