@Override @SuppressWarnings("unchecked") public Set<Class<? extends NotificationId>> getTypeClasses() { return Util.<Class<? extends NotificationId>> asSet(NotificationId.class); }
public static void confirmTopologyUpdate(CacheTopology.Phase phase, BlockingLocalTopologyManager... topologyManagers) throws InterruptedException { for (BlockingLocalTopologyManager topologyManager : topologyManagers) { topologyManager.expectTopologyUpdate(phase).unblock(); } if (needConfirmation(phase)) { for (BlockingLocalTopologyManager topologyManager : topologyManagers) { topologyManager.expectPhaseConfirmation().unblock(); } } }
/** * Wait for all the responses. */ public BlockedResponseMap expectAllResponses() { return uncheckedGet(expectAllResponsesAsync()); }
/** * Avoid sending the request, and finish it with the given responses instead. */ public FakeResponses skipSend() { log.tracef("Not sending request %s", request.getCommand()); request.skipSend(); if (request.hasCollector()) { return new FakeResponses(request); } else { return null; } }
public BlockedTopology expectRebalanceStartAfterLeave() throws InterruptedException { // After a node leaves, the coordinator sends a NO_REBALANCE topology update with the remaining members // Then it immediately starts the rebalance with a READ_OLD topology update // The members can receive the topology updates in either order BlockedTopology topology0 = expectTopologyUpdate(); if (topology0.getType() == Type.REBALANCE_START) { expectTopologyUpdate(CacheTopology.Phase.NO_REBALANCE).unblock(); } else { topology0.unblock(); topology0 = expectTopologyUpdate(CacheTopology.Phase.READ_OLD_WRITE_ALL); } return topology0; }
@Override public CH create(Hash hashFunction, int numOwners, int numSegments, List<Address> members, Map<Address, Float> capacityFactors) { assertNumberOfSegments(numSegments); List<Address>[] segmentOwners = assignSegments(numSegments, numOwners, members); return create(hashFunction, numOwners, numSegments, members, capacityFactors, segmentOwners, false); }
/** * Wait for a response from {@code sender}, but keep the request blocked. */ public BlockedResponse expectResponse(Address sender) { return uncheckedGet(expectResponseAsync(sender)); }
/** * Wait for all the responses and process them. */ public void receiveAll() { expectAllResponses().receive(); }
/** * To be overridden if the store requires special time handling */ protected ControlledTimeService getTimeService() { return new ControlledTimeService(); }
/** * Expect a command to be invoked remotely and send replies using the {@link BlockedRequest} methods. */ public <T extends ReplicableCommand> BlockedRequest expectCommand(Class<T> expectedCommandClass) { return uncheckedGet(expectCommandAsync(expectedCommandClass)); }
public BlockingTransport(Transport actual) { super(actual); notifierLatch = new NotifierLatch(); notifierLatch.stopBlocking(); }
public void skipSendAndReceiveAsync(Address target, Response fakeResponse) { requests.get(target).skipSend().receiveAsync(target, fakeResponse); } }
/** * Create a consistent hash factory with a single segment. */ public ControlledConsistentHashFactory(Trait<CH> trait, int primaryOwnerIndex, int... backupOwnerIndexes) { super(trait, 1); setOwnerIndexes(primaryOwnerIndex, backupOwnerIndexes); }
@Override protected void beforeBackupRemotely(XSiteReplicateCommand command) { if (command instanceof XSiteStatePushCommand) { notifierLatch.blockIfNeeded(); } } }
public void unblock() { event.unblock(); } }
@Override protected <T> void performSend(Collection<Address> targets, ReplicableCommand command, Function<ResponseCollector<T>, CompletionStage<T>> invoker) { performRequest(targets, command, null, invoker, null); }
/** * Wait for a {@code CacheNotFoundResponse} from {@code sender}, but keep the request blocked. */ public BlockedResponse expectLeaver(Address a) { return expectResponse(a, CacheNotFoundResponse.INSTANCE); }
/** * Complete a request after expecting and receiving responses individually, e.g. with * {@link #expectResponse(Address)}. * * This method blocks until all the responses have been received internally, but doesn't pass them on * to the original response collector (it only calls {@link ResponseCollector#finish()}). */ public void finish() { request.collectFinish(); }
/** * Expect a topology updates and unblock it. * <p> * If the update requires confirmation, unblock the confirmation as well. */ public void confirmTopologyUpdate(CacheTopology.Phase phase) throws InterruptedException { expectTopologyUpdate(phase).unblock(); if (needConfirmation(phase)) { expectPhaseConfirmation().unblock(); } }
/** * Wait for a response from {@code sender}, but keep the request blocked. */ public BlockedResponse expectResponse(Address sender, Consumer<Response> checker) { BlockedResponse br = uncheckedGet(expectResponseAsync(sender)); checker.accept(br.response); return br; }