Search in sources :

Example 1 with TransportAddressConnector

use of org.elasticsearch.discovery.PeerFinder.TransportAddressConnector in project crate by crate.

the class PeerFinderTests method setup.

@Before
public void setup() {
    capturingTransport = new CapturingTransport();
    transportAddressConnector = new MockTransportAddressConnector();
    providedAddresses = new ArrayList<>();
    addressResolveDelay = 0L;
    final Settings settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), "node").build();
    deterministicTaskQueue = new DeterministicTaskQueue(settings, random());
    localNode = newDiscoveryNode("local-node");
    ConnectionManager innerConnectionManager = new ConnectionManager(settings, capturingTransport);
    StubbableConnectionManager connectionManager = new StubbableConnectionManager(innerConnectionManager, settings, capturingTransport, deterministicTaskQueue.getThreadPool());
    connectionManager.setDefaultNodeConnectedBehavior(cm -> {
        assertTrue(Sets.haveEmptyIntersection(connectedNodes, disconnectedNodes));
        return connectedNodes;
    });
    connectionManager.setDefaultGetConnectionBehavior((cm, discoveryNode) -> capturingTransport.createConnection(discoveryNode));
    transportService = new TransportService(settings, capturingTransport, deterministicTaskQueue.getThreadPool(), boundTransportAddress -> localNode, null, connectionManager);
    transportService.start();
    transportService.acceptIncomingRequests();
    lastAcceptedNodes = DiscoveryNodes.builder().localNodeId(localNode.getId()).add(localNode).build();
    peerFinder = new TestPeerFinder(settings, transportService, transportAddressConnector);
    foundPeersFromNotification = emptyList();
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) Arrays(java.util.Arrays) Builder(org.elasticsearch.cluster.node.DiscoveryNodes.Builder) Matchers.emptyArray(org.hamcrest.Matchers.emptyArray) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) Collections.singletonList(java.util.Collections.singletonList) Sets(io.crate.common.collections.Sets) Settings(org.elasticsearch.common.settings.Settings) After(org.junit.After) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) DeterministicTaskQueue(org.elasticsearch.cluster.coordination.DeterministicTaskQueue) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) ConnectionManager(org.elasticsearch.transport.ConnectionManager) Collectors(java.util.stream.Collectors) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) Version(org.elasticsearch.Version) Stream(java.util.stream.Stream) TransportAddress(org.elasticsearch.common.transport.TransportAddress) NODE_NAME_SETTING(org.elasticsearch.node.Node.NODE_NAME_SETTING) Matchers.contains(org.hamcrest.Matchers.contains) PeersResponse(org.elasticsearch.cluster.coordination.PeersResponse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) REQUEST_PEERS_ACTION_NAME(org.elasticsearch.discovery.PeerFinder.REQUEST_PEERS_ACTION_NAME) TransportException(org.elasticsearch.transport.TransportException) CapturedRequest(org.elasticsearch.test.transport.CapturingTransport.CapturedRequest) TransportAddressConnector(org.elasticsearch.discovery.PeerFinder.TransportAddressConnector) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Names(org.elasticsearch.threadpool.ThreadPool.Names) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OptionalLong(java.util.OptionalLong) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) StreamSupport(java.util.stream.StreamSupport) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) Before(org.junit.Before) StubbableConnectionManager(org.elasticsearch.test.transport.StubbableConnectionManager) Collections.emptyMap(java.util.Collections.emptyMap) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Matchers.empty(org.hamcrest.Matchers.empty) Collections.emptySet(java.util.Collections.emptySet) IOException(java.io.IOException) Consumer(java.util.function.Consumer) StreamInput(org.elasticsearch.common.io.stream.StreamInput) Collections(java.util.Collections) ActionListener(org.elasticsearch.action.ActionListener) ConnectionManager(org.elasticsearch.transport.ConnectionManager) StubbableConnectionManager(org.elasticsearch.test.transport.StubbableConnectionManager) StubbableConnectionManager(org.elasticsearch.test.transport.StubbableConnectionManager) DeterministicTaskQueue(org.elasticsearch.cluster.coordination.DeterministicTaskQueue) TransportService(org.elasticsearch.transport.TransportService) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) Settings(org.elasticsearch.common.settings.Settings) Before(org.junit.Before)

Aggregations

Sets (io.crate.common.collections.Sets)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.emptySet (java.util.Collections.emptySet)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 OptionalLong (java.util.OptionalLong)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1