Java Code Examples for io.atomix.cluster.MemberId#from()
The following examples show how to use
io.atomix.cluster.MemberId#from() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrimaryTermTest.java From atomix with Apache License 2.0 | 6 votes |
@Test public void testPrimaryTerm() throws Exception { GroupMember primary = new GroupMember(MemberId.from("1"), MemberGroupId.from("1")); List<GroupMember> candidates = Arrays.asList( new GroupMember(MemberId.from("1"), MemberGroupId.from("1")), new GroupMember(MemberId.from("2"), MemberGroupId.from("2")), new GroupMember(MemberId.from("3"), MemberGroupId.from("2")), new GroupMember(MemberId.from("4"), MemberGroupId.from("3")), new GroupMember(MemberId.from("5"), MemberGroupId.from("3"))); PrimaryTerm term = new PrimaryTerm(1, primary, candidates); assertEquals(primary, term.primary()); assertEquals(candidates, term.candidates()); assertEquals(Arrays.asList(), term.backups(0)); assertEquals(Arrays.asList(candidates.get(1)), term.backups(1)); assertEquals(Arrays.asList(candidates.get(1), candidates.get(2)), term.backups(2)); assertEquals(Arrays.asList(candidates.get(1), candidates.get(2), candidates.get(3)), term.backups(3)); assertEquals(Arrays.asList(candidates.get(1), candidates.get(2), candidates.get(3), candidates.get(4)), term.backups(4)); assertEquals(Arrays.asList(candidates.get(1), candidates.get(2), candidates.get(3), candidates.get(4)), term.backups(5)); }
Example 2
Source File: RaftSessionRegistryTest.java From atomix with Apache License 2.0 | 6 votes |
private RaftSession createSession(long sessionId) { RaftServiceContext context = mock(RaftServiceContext.class); when(context.serviceType()).thenReturn(TestPrimitiveType.instance()); when(context.serviceName()).thenReturn("test"); when(context.serviceId()).thenReturn(PrimitiveId.from(1)); RaftContext server = mock(RaftContext.class); when(server.getProtocol()).thenReturn(mock(RaftServerProtocol.class)); RaftServiceManager manager = mock(RaftServiceManager.class); when(manager.executor()).thenReturn(mock(ThreadContext.class)); when(server.getServiceManager()).thenReturn(manager); return new RaftSession( SessionId.from(sessionId), MemberId.from("1"), "test", TestPrimitiveType.instance(), ReadConsistency.LINEARIZABLE, 100, 5000, System.currentTimeMillis(), Serializer.using(Namespaces.BASIC), context, server, mock(ThreadContextFactory.class)); }
Example 3
Source File: TestAtomixFactory.java From atomix with Apache License 2.0 | 5 votes |
/** * Returns a new Atomix instance. * * @return a new Atomix instance */ public Atomix newInstance() { int id = memberId.incrementAndGet(); return new TestAtomix( MemberId.from(String.valueOf(id)), Address.from("localhost", 5000 + id), messagingServiceFactory, unicastServiceFactory, broadcastServiceFactory); }
Example 4
Source File: SwimProtocolTest.java From atomix with Apache License 2.0 | 5 votes |
private Member member(String id, String host, int port, Version version) { return new SwimMembershipProtocol.SwimMember( MemberId.from(id), new Address(host, port), null, null, null, new Properties(), version, System.currentTimeMillis()); }
Example 5
Source File: SwimMembershipProtocol.java From atomix with Apache License 2.0 | 5 votes |
/** * Handles a node join event. */ private void handleJoinEvent(Node node) { SwimMember member = new SwimMember(MemberId.from(node.id().id()), node.address()); if (!members.containsKey(member.id())) { probe(member.copy()); } }
Example 6
Source File: HeartbeatMembershipProtocol.java From atomix with Apache License 2.0 | 5 votes |
/** * Handles a node join event. */ private void handleJoinEvent(Node node) { GossipMember member = new GossipMember(MemberId.from(node.id().id()), node.address()); if (!members.containsKey(member.id())) { sendHeartbeat(member); } }
Example 7
Source File: AtomixAgent.java From atomix with Apache License 2.0 | 5 votes |
static MemberId parseMemberId(String address) { int endIndex = address.indexOf('@'); if (endIndex > 0) { return MemberId.from(address.substring(0, endIndex)); } return null; }
Example 8
Source File: RaftServiceManagerTest.java From atomix with Apache License 2.0 | 5 votes |
@Before public void setupContext() throws IOException { deleteStorage(); RaftStorage storage = RaftStorage.builder() .withPrefix("test") .withDirectory(PATH.toFile()) .withNamespace(NAMESPACE) .build(); PrimitiveTypeRegistry registry = new PrimitiveTypeRegistry() { @Override public Collection<PrimitiveType> getPrimitiveTypes() { return Collections.singleton(new TestType()); } @Override public PrimitiveType getPrimitiveType(String typeName) { return new TestType(); } }; raft = new RaftContext( "test", MemberId.from("test-1"), mock(ClusterMembershipService.class), mock(RaftServerProtocol.class), storage, registry, ThreadModel.SHARED_THREAD_POOL.factory("raft-server-test-%d", 1, LoggerFactory.getLogger(RaftServer.class)), true); snapshotTaken = new AtomicBoolean(); snapshotInstalled = new AtomicBoolean(); }
Example 9
Source File: TestProtocolService.java From atomix with Apache License 2.0 | 4 votes |
@Override public MemberId localMemberId() { return MemberId.from("test"); }
Example 10
Source File: PrimaryElectorServiceTest.java From atomix with Apache License 2.0 | 4 votes |
GroupMember createGroupMember(String id, String groupId) { return new GroupMember(MemberId.from(id), groupId != null ? MemberGroupId.from(groupId) : null); }
Example 11
Source File: RaftServiceContext.java From atomix with Apache License 2.0 | 4 votes |
/** * Installs a snapshot. */ public void installSnapshot(SnapshotReader reader) { log.debug("Installing snapshot {}", reader.snapshot().index()); reader.skip(Bytes.LONG); // Skip the service ID PrimitiveType primitiveType; try { primitiveType = raft.getPrimitiveTypes().getPrimitiveType(reader.readString()); } catch (ConfigurationException e) { log.error(e.getMessage(), e); return; } String serviceName = reader.readString(); currentIndex = reader.readLong(); currentTimestamp = reader.readLong(); timestampDelta = reader.readLong(); int sessionCount = reader.readInt(); for (int i = 0; i < sessionCount; i++) { SessionId sessionId = SessionId.from(reader.readLong()); MemberId node = MemberId.from(reader.readString()); ReadConsistency readConsistency = ReadConsistency.valueOf(reader.readString()); long minTimeout = reader.readLong(); long maxTimeout = reader.readLong(); long sessionTimestamp = reader.readLong(); // Only create a new session if one does not already exist. This is necessary to ensure only a single session // is ever opened and exposed to the state machine. RaftSession session = raft.getSessions().addSession(new RaftSession( sessionId, node, serviceName, primitiveType, readConsistency, minTimeout, maxTimeout, sessionTimestamp, service.serializer(), this, raft, threadContextFactory)); session.setRequestSequence(reader.readLong()); session.setCommandSequence(reader.readLong()); session.setEventIndex(reader.readLong()); session.setLastCompleted(reader.readLong()); session.setLastApplied(reader.snapshot().index()); session.setLastUpdated(sessionTimestamp); session.open(); service.register(sessions.addSession(session)); } service.restore(new DefaultBackupInput(reader, service.serializer())); }
Example 12
Source File: RaftTest.java From atomix with Apache License 2.0 | 2 votes |
/** * Returns the next unique member identifier. * * @return The next unique member identifier. */ private MemberId nextNodeId() { return MemberId.from(String.valueOf(++nextId)); }
Example 13
Source File: MetaStore.java From atomix with Apache License 2.0 | 2 votes |
/** * Loads the last vote for the server. * * @return The last vote for the server. */ public synchronized MemberId loadVote() { String id = metadataBuffer.readString(8); return id != null ? MemberId.from(id) : null; }
Example 14
Source File: DistributedLogTest.java From atomix with Apache License 2.0 | 2 votes |
/** * Returns the next unique member identifier. * * @return The next unique member identifier. */ private MemberId nextMemberId() { return MemberId.from(String.valueOf(++memberId)); }
Example 15
Source File: RaftFuzzTest.java From atomix with Apache License 2.0 | 2 votes |
/** * Returns the next unique member identifier. * * @return The next unique member identifier. */ private MemberId nextNodeId() { return MemberId.from(String.valueOf(++nextId)); }
Example 16
Source File: VoteRequest.java From atomix with Apache License 2.0 | 2 votes |
/** * Returns the candidate's address. * * @return The candidate's address. */ public MemberId candidate() { return MemberId.from(candidate); }
Example 17
Source File: ConfigureRequest.java From atomix with Apache License 2.0 | 2 votes |
/** * Returns the requesting leader address. * * @return The leader's address. */ public MemberId leader() { return MemberId.from(leader); }
Example 18
Source File: AppendRequest.java From atomix with Apache License 2.0 | 2 votes |
/** * Returns the requesting leader address. * * @return The leader's address. */ public MemberId leader() { return MemberId.from(leader); }
Example 19
Source File: PollRequest.java From atomix with Apache License 2.0 | 2 votes |
/** * Returns the candidate's address. * * @return The candidate's address. */ public MemberId candidate() { return MemberId.from(candidate); }
Example 20
Source File: PrimaryBackupTest.java From atomix with Apache License 2.0 | 2 votes |
/** * Returns the next unique member identifier. * * @return The next unique member identifier. */ private MemberId nextMemberId() { return MemberId.from(String.valueOf(++memberId)); }