Search in sources :

Example 16 with SocketAddress

use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.

the class InvitationRequest method wrap.

@Override
public void wrap(final DirectBuffer buffer, int offset, final int length) {
    final int frameEnd = offset + length;
    headerDecoder.wrap(buffer, offset);
    offset += headerDecoder.encodedLength();
    bodyDecoder.wrap(buffer, offset, headerDecoder.blockLength(), headerDecoder.version());
    partitionId = bodyDecoder.partitionId();
    term = bodyDecoder.term();
    members.clear();
    final Iterator<MembersDecoder> iterator = bodyDecoder.members().iterator();
    while (iterator.hasNext()) {
        final MembersDecoder decoder = iterator.next();
        final SocketAddress member = new SocketAddress();
        member.port(decoder.port());
        final MutableDirectBuffer hostBuffer = member.getHostBuffer();
        final int hostLength = decoder.hostLength();
        member.hostLength(hostLength);
        decoder.getHost(hostBuffer, 0, hostLength);
        members.add(member);
    }
    final int topicNameLength = bodyDecoder.topicNameLength();
    final int topicNameOffset = bodyDecoder.limit() + topicNameHeaderLength();
    topicName.wrap(buffer, topicNameOffset, topicNameLength);
    // skip topic name in decoder
    bodyDecoder.limit(topicNameOffset + topicNameLength);
    assert bodyDecoder.limit() == frameEnd : "Decoder read only to position " + bodyDecoder.limit() + " but expected " + frameEnd + " as final position";
}
Also used : MembersDecoder(io.zeebe.clustering.management.InvitationRequestDecoder.MembersDecoder) SocketAddress(io.zeebe.transport.SocketAddress) MutableDirectBuffer(org.agrona.MutableDirectBuffer)

Example 17 with SocketAddress

use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.

the class RaftConfigurationMetadata method getMembers.

public List<SocketAddress> getMembers() {
    final List<SocketAddress> members = new ArrayList<>();
    final Iterator<RaftConfigurationMetadataMember> iterator = membersProp.iterator();
    while (iterator.hasNext()) {
        final RaftConfigurationMetadataMember configurationMember = iterator.next();
        final DirectBuffer hostBuffer = configurationMember.getHost();
        final SocketAddress member = new SocketAddress().host(hostBuffer, 0, hostBuffer.capacity()).port(configurationMember.getPort());
        members.add(member);
    }
    return members;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) ArrayList(java.util.ArrayList) SocketAddress(io.zeebe.transport.SocketAddress)

Example 18 with SocketAddress

use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.

the class CreateTopicClusteredTest method shouldChooseNewLeaderForCreatedTopicAfterLeaderDies.

@Test
public void shouldChooseNewLeaderForCreatedTopicAfterLeaderDies() {
    // given
    final int partitionsCount = 1;
    clusteringRule.createTopic("foo", partitionsCount);
    final TaskEvent taskEvent = client.tasks().create("foo", "bar").execute();
    final int partitionId = taskEvent.getMetadata().getPartitionId();
    final TopologyBroker leaderForPartition = clusteringRule.getLeaderForPartition(partitionId);
    final SocketAddress currentLeaderAddress = leaderForPartition.getSocketAddress();
    // when
    clusteringRule.stopBroker(currentLeaderAddress);
    // then
    final TopologyBroker newLeader = clusteringRule.getLeaderForPartition(partitionId);
    assertThat(newLeader.getSocketAddress()).isNotEqualTo(leaderForPartition.getSocketAddress());
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) SocketAddress(io.zeebe.transport.SocketAddress) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test)

Example 19 with SocketAddress

use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.

the class GossipClusteringTest method shouldRemoveMemberFromTopology.

@Test
public void shouldRemoveMemberFromTopology() {
    // given
    final SocketAddress brokerAddress = ClusteringRule.BROKER_3_CLIENT_ADDRESS;
    final SocketAddress[] otherBrokers = clusteringRule.getOtherBrokers(brokerAddress);
    // when
    clusteringRule.stopBroker(brokerAddress);
    // then
    final List<SocketAddress> topologyBrokers = clusteringRule.getBrokersInCluster();
    assertThat(topologyBrokers).containsExactlyInAnyOrder(otherBrokers);
}
Also used : SocketAddress(io.zeebe.transport.SocketAddress) Test(org.junit.Test)

Example 20 with SocketAddress

use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.

the class GossipClusteringTest method shouldRemoveLeaderFromCluster.

@Test
public void shouldRemoveLeaderFromCluster() {
    // given
    final TopologyBroker leaderForPartition = clusteringRule.getLeaderForPartition(0);
    final SocketAddress[] otherBrokers = clusteringRule.getOtherBrokers(leaderForPartition.getSocketAddress());
    // when
    clusteringRule.stopBroker(leaderForPartition.getSocketAddress());
    // then
    final List<SocketAddress> topologyBrokers = clusteringRule.getBrokersInCluster();
    assertThat(topologyBrokers).containsExactlyInAnyOrder(otherBrokers);
}
Also used : SocketAddress(io.zeebe.transport.SocketAddress) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test)

Aggregations

SocketAddress (io.zeebe.transport.SocketAddress)21 Test (org.junit.Test)13 TopologyBroker (io.zeebe.client.clustering.impl.TopologyBroker)6 TaskEvent (io.zeebe.client.event.TaskEvent)3 DirectBuffer (org.agrona.DirectBuffer)3 TopologyBroker (io.zeebe.broker.clustering.handler.TopologyBroker)2 TypedBatchWriter (io.zeebe.broker.logstreams.processor.TypedBatchWriter)2 Raft (io.zeebe.raft.Raft)2 TestUtil.doRepeatedly (io.zeebe.test.util.TestUtil.doRepeatedly)2 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 MutableDirectBuffer (org.agrona.MutableDirectBuffer)2 Before (org.junit.Before)2 Topology (io.zeebe.broker.clustering.handler.Topology)1 Member (io.zeebe.broker.clustering.member.Member)1 ClientRule (io.zeebe.broker.it.ClientRule)1 BROKER_1_CLIENT_ADDRESS (io.zeebe.broker.it.clustering.ClusteringRule.BROKER_1_CLIENT_ADDRESS)1 TypedEvent (io.zeebe.broker.logstreams.processor.TypedEvent)1 TypedStreamEnvironment (io.zeebe.broker.logstreams.processor.TypedStreamEnvironment)1