use of com.twitter.common.base.Supplier in project commons by twitter.
the class GroupTest method testUpdateMembershipData.
@Test
public void testUpdateMembershipData() throws Exception {
Supplier<byte[]> dataSupplier = new EasyMockTest.Clazz<Supplier<byte[]>>() {
}.createMock();
byte[] initial = "start".getBytes();
expect(dataSupplier.get()).andReturn(initial);
byte[] second = "update".getBytes();
expect(dataSupplier.get()).andReturn(second);
replay(dataSupplier);
Membership membership = joinGroup.join(dataSupplier, onLoseMembership);
assertArrayEquals("Initial setting is incorrect.", initial, zkClient.get().getData(membership.getMemberPath(), false, null));
assertArrayEquals("Updating supplier should not change membership data", initial, zkClient.get().getData(membership.getMemberPath(), false, null));
membership.updateMemberData();
assertArrayEquals("Updating membership should change data", second, zkClient.get().getData(membership.getMemberPath(), false, null));
verify(dataSupplier);
}
use of com.twitter.common.base.Supplier in project commons by twitter.
the class ServerSetImpl method join.
private EndpointStatus join(InetSocketAddress endpoint, Map<String, InetSocketAddress> additionalEndpoints, Optional<Integer> shardId) throws JoinException, InterruptedException {
checkNotNull(endpoint);
checkNotNull(additionalEndpoints);
final MemberStatus memberStatus = new MemberStatus(endpoint, additionalEndpoints, shardId);
Supplier<byte[]> serviceInstanceSupplier = new Supplier<byte[]>() {
@Override
public byte[] get() {
return memberStatus.serializeServiceInstance();
}
};
final Membership membership = group.join(serviceInstanceSupplier);
return new EndpointStatus() {
@Override
public void update(Status status) throws UpdateException {
checkNotNull(status);
LOG.warning("This method is deprecated. Please use leave() instead.");
if (status == Status.DEAD) {
leave();
} else {
LOG.warning("Status update has been ignored");
}
}
@Override
public void leave() throws UpdateException {
memberStatus.leave(membership);
}
};
}
Aggregations