Search in sources :

Example 1 with XSiteBackup

use of org.infinispan.xsite.XSiteBackup in project infinispan by infinispan.

the class JGroupsBackupResponseUnitTest method testAsyncListener.

public void testAsyncListener() {
    Listener listener = new Listener();
    long sendTimestamp = timeService.time();
    List<XSiteBackup> backups = new ArrayList<>(2);
    backups.add(createAsyncBackup("async-1"));
    backups.add(createAsyncBackup("async-2"));
    Map<XSiteBackup, CompletableFuture<ValidResponse>> responses = createResponseMap(backups);
    BackupResponse backupResponse = newBackupResponse(responses);
    backupResponse.notifyAsyncAck(listener);
    assertTrue(listener.queue.isEmpty());
    timeService.advance(10);
    responses.get(backups.get(0)).complete(null);
    assertListenerData(listener, sendTimestamp, "async-1", null);
    timeService.advance(10);
    CacheException exception = new CacheException("Test-Exception");
    responses.get(backups.get(1)).completeExceptionally(exception);
    assertListenerData(listener, sendTimestamp, "async-2", exception);
    assertTrue(listener.queue.isEmpty());
    assertEquals(TimeUnit.NANOSECONDS.toMillis(sendTimestamp), backupResponse.getSendTimeMillis());
}
Also used : XSiteBackup(org.infinispan.xsite.XSiteBackup) CompletableFuture(java.util.concurrent.CompletableFuture) XSiteAsyncAckListener(org.infinispan.remoting.transport.XSiteAsyncAckListener) CacheException(org.infinispan.commons.CacheException) ArrayList(java.util.ArrayList) BackupResponse(org.infinispan.remoting.transport.BackupResponse)

Example 2 with XSiteBackup

use of org.infinispan.xsite.XSiteBackup in project infinispan by infinispan.

the class JGroupsBackupResponseUnitTest method testNoWaitForAsyncWith.

public void testNoWaitForAsyncWith() {
    List<XSiteBackup> backups = Collections.singletonList(createAsyncBackup("async-only"));
    Map<XSiteBackup, CompletableFuture<ValidResponse>> responses = createResponseMap(backups);
    BackupResponse response = newBackupResponse(responses);
    Future<Void> waiting = waitBackupResponse(response);
    // we only have async. it should be completed
    assertCompleted(waiting);
}
Also used : XSiteBackup(org.infinispan.xsite.XSiteBackup) CompletableFuture(java.util.concurrent.CompletableFuture) BackupResponse(org.infinispan.remoting.transport.BackupResponse)

Example 3 with XSiteBackup

use of org.infinispan.xsite.XSiteBackup in project infinispan by infinispan.

the class JGroupsBackupResponseUnitTest method testSyncListener.

public void testSyncListener() {
    Listener listener = new Listener();
    List<XSiteBackup> backups = new ArrayList<>(2);
    backups.add(createSyncBackup("sync-1", 10000));
    backups.add(createAsyncBackup("async-2"));
    Map<XSiteBackup, CompletableFuture<ValidResponse>> responses = createResponseMap(backups);
    BackupResponse backupResponse = newBackupResponse(responses);
    backupResponse.notifyFinish(listener);
    assertTrue(listener.queue.isEmpty());
    Future<Void> waiting = waitBackupResponse(backupResponse);
    timeService.advance(10);
    responses.get(backups.get(1)).complete(null);
    assertNotCompleted(waiting);
    assertTrue(listener.queue.isEmpty());
    timeService.advance(10);
    responses.get(backups.get(0)).complete(null);
    assertCompleted(waiting);
    assertListenerData(listener, 20, null, null);
    assertTrue(listener.queue.isEmpty());
}
Also used : XSiteBackup(org.infinispan.xsite.XSiteBackup) CompletableFuture(java.util.concurrent.CompletableFuture) XSiteAsyncAckListener(org.infinispan.remoting.transport.XSiteAsyncAckListener) ArrayList(java.util.ArrayList) BackupResponse(org.infinispan.remoting.transport.BackupResponse)

Example 4 with XSiteBackup

use of org.infinispan.xsite.XSiteBackup in project infinispan by infinispan.

the class JGroupsBackupResponseUnitTest method testNoErrorsFromAsync.

public void testNoErrorsFromAsync() {
    // tests if JGroupsBackupResponse doesn't waitBackupResponse for the async request
    long timeoutMs = 10000;
    List<XSiteBackup> backups = new ArrayList<>(3);
    backups.add(createSyncBackup("sync-1", timeoutMs));
    backups.add(createSyncBackup("sync-2", 2 * timeoutMs));
    backups.add(createAsyncBackup("async"));
    Map<XSiteBackup, CompletableFuture<ValidResponse>> responses = createResponseMap(backups);
    BackupResponse response = newBackupResponse(responses);
    // this will trigger a timeout for sync-1
    timeService.advance(timeoutMs + 1);
    Future<Void> waiting = waitBackupResponse(response);
    assertNotCompleted(waiting);
    // complete the async request
    CacheException exception = new CacheException("Test-Exception");
    responses.get(backups.get(1)).complete(null);
    responses.get(backups.get(2)).completeExceptionally(exception);
    assertCompleted(waiting);
    assertEquals(1, response.getCommunicationErrors().size());
    assertEquals(1, response.getFailedBackups().size());
    assertTrue(response.getCommunicationErrors().contains("sync-1"));
    assertTrue(response.getFailedBackups().containsKey("sync-1"));
    assertException(org.infinispan.util.concurrent.TimeoutException.class, response.getFailedBackups().get("sync-1"));
}
Also used : XSiteBackup(org.infinispan.xsite.XSiteBackup) CompletableFuture(java.util.concurrent.CompletableFuture) CacheException(org.infinispan.commons.CacheException) ArrayList(java.util.ArrayList) BackupResponse(org.infinispan.remoting.transport.BackupResponse)

Example 5 with XSiteBackup

use of org.infinispan.xsite.XSiteBackup in project infinispan by infinispan.

the class SiteProviderTopologyChangeTest method doTopologyChangeDuringXSiteStateTransfer.

/**
 * the test node starts the x-site state transfer and sends a chunk of data. the next chunk is blocked and we trigger
 * the cache topology change.
 */
private void doTopologyChangeDuringXSiteStateTransfer(TopologyEvent event) throws Exception {
    log.debugf("Start topology change during x-site state transfer with %s", event);
    initBeforeTest();
    final TestCaches<Object, Object> testCaches = createTestCache(event, LON);
    log.debugf("Controlled cache=%s, Coordinator cache=%s, Cache to remove=%s", addressOf(testCaches.controllerCache), addressOf(testCaches.coordinator), testCaches.removeIndex < 0 ? "NONE" : addressOf(cache(LON, testCaches.removeIndex)));
    // the test node will start the x-site state transfer and it will block. next, it the topology will change.
    // strategy: let the first push command to proceed a block the next one.
    final CheckPoint checkPoint = new CheckPoint();
    final AtomicBoolean firstChunk = new AtomicBoolean(false);
    wrapGlobalComponent(testCaches.controllerCache.getCacheManager(), Transport.class, new WrapFactory<Transport, Transport, CacheContainer>() {

        @Override
        public Transport wrap(CacheContainer wrapOn, Transport current) {
            return new AbstractDelegatingTransport(current) {

                @Override
                public void start() {
                // no-op; avoid re-start the transport again...
                }

                @Override
                public XSiteResponse backupRemotely(XSiteBackup backup, XSiteReplicateCommand rpcCommand) {
                    if (rpcCommand instanceof XSiteStatePushCommand) {
                        if (firstChunk.compareAndSet(false, true)) {
                            checkPoint.trigger("before-second-chunk");
                            try {
                                checkPoint.awaitStrict("second-chunk", 30, TimeUnit.SECONDS);
                            } catch (InterruptedException | TimeoutException e) {
                                XSiteResponseImpl rsp = new XSiteResponseImpl(TIME_SERVICE, backup);
                                rsp.completeExceptionally(e);
                                return rsp;
                            }
                        }
                    }
                    return super.backupRemotely(backup, rpcCommand);
                }
            };
        }
    }, true);
    log.debug("Start x-site state transfer");
    startStateTransfer(testCaches.coordinator, NYC);
    assertOnline(LON, NYC);
    checkPoint.awaitStrict("before-second-chunk", 30, TimeUnit.SECONDS);
    final Future<Void> topologyEventFuture = triggerTopologyChange(LON, testCaches.removeIndex);
    topologyEventFuture.get();
    checkPoint.triggerForever("second-chunk");
    awaitLocalStateTransfer(LON);
    awaitXSiteStateSent(LON);
    assertData();
}
Also used : XSiteBackup(org.infinispan.xsite.XSiteBackup) XSiteReplicateCommand(org.infinispan.xsite.XSiteReplicateCommand) AbstractDelegatingTransport(org.infinispan.remoting.transport.AbstractDelegatingTransport) CacheContainer(org.infinispan.manager.CacheContainer) XSiteResponse(org.infinispan.remoting.transport.XSiteResponse) XSiteResponseImpl(org.infinispan.remoting.transport.impl.XSiteResponseImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AbstractDelegatingTransport(org.infinispan.remoting.transport.AbstractDelegatingTransport) Transport(org.infinispan.remoting.transport.Transport) XSiteStatePushCommand(org.infinispan.xsite.statetransfer.XSiteStatePushCommand) CheckPoint(org.infinispan.test.fwk.CheckPoint)

Aggregations

XSiteBackup (org.infinispan.xsite.XSiteBackup)11 CompletableFuture (java.util.concurrent.CompletableFuture)9 BackupResponse (org.infinispan.remoting.transport.BackupResponse)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 Map (java.util.Map)3 XSiteAsyncAckListener (org.infinispan.remoting.transport.XSiteAsyncAckListener)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CacheException (org.infinispan.commons.CacheException)2 Transport (org.infinispan.remoting.transport.Transport)2 XSiteResponse (org.infinispan.remoting.transport.XSiteResponse)2 XSiteReplicateCommand (org.infinispan.xsite.XSiteReplicateCommand)2 Completable (io.reactivex.rxjava3.core.Completable)1 Flowable (io.reactivex.rxjava3.core.Flowable)1 Collection (java.util.Collection)1 Objects (java.util.Objects)1 PrimitiveIterator (java.util.PrimitiveIterator)1 CompletionStage (java.util.concurrent.CompletionStage)1 ExecutionException (java.util.concurrent.ExecutionException)1