Search in sources :

Example 1 with ConcurrentGlobalContainer

use of org.infinispan.extendedstats.container.ConcurrentGlobalContainer in project infinispan by infinispan.

the class ConcurrentContainerTest method testIsolationWithResetMerge.

public void testIsolationWithResetMerge() {
    final ConcurrentGlobalContainer globalContainer = new ConcurrentGlobalContainer(TIME_SERVICE);
    final List<StatisticsSnapshot> snapshots = new ArrayList<>(4);
    snapshots.add(globalContainer.getSnapshot());
    // two random stats, one local and one remote
    final ExtendedStatistic localStat = ExtendedStatistic.PREPARE_COMMAND_SIZE;
    final ExtendedStatistic remoteStat = ExtendedStatistic.NUM_COMMITTED_WR_TX;
    Assert.assertTrue(localStat.isLocal());
    Assert.assertTrue(remoteStat.isRemote());
    globalContainer.add(localStat, 10, true);
    globalContainer.add(remoteStat, 20, false);
    snapshots.add(globalContainer.getSnapshot());
    assertSnapshotValues(snapshots, Arrays.asList(0D, 10D), localStat, true);
    assertSnapshotValues(snapshots, Arrays.asList(0D, 20D), remoteStat, false);
    globalContainer.reset();
    snapshots.add(globalContainer.getSnapshot());
    assertSnapshotValues(snapshots, Arrays.asList(0D, 10D, 0D), localStat, true);
    assertSnapshotValues(snapshots, Arrays.asList(0D, 20D, 0D), remoteStat, false);
    globalContainer.add(localStat, 10, true);
    globalContainer.add(remoteStat, 20, false);
    snapshots.add(globalContainer.getSnapshot());
    assertSnapshotValues(snapshots, Arrays.asList(0D, 10D, 0D, 10D), localStat, true);
    assertSnapshotValues(snapshots, Arrays.asList(0D, 20D, 0D, 20D), remoteStat, false);
    assertFinalState(globalContainer);
}
Also used : ExtendedStatistic(org.infinispan.extendedstats.container.ExtendedStatistic) StatisticsSnapshot(org.infinispan.extendedstats.container.StatisticsSnapshot) ArrayList(java.util.ArrayList) ConcurrentGlobalContainer(org.infinispan.extendedstats.container.ConcurrentGlobalContainer)

Example 2 with ConcurrentGlobalContainer

use of org.infinispan.extendedstats.container.ConcurrentGlobalContainer in project infinispan by infinispan.

the class ConcurrentContainerTest method testIsolationWithTransactionMerge.

public void testIsolationWithTransactionMerge() {
    final ConcurrentGlobalContainer globalContainer = new ConcurrentGlobalContainer(TIME_SERVICE);
    final List<StatisticsSnapshot> snapshots = new ArrayList<>(4);
    snapshots.add(globalContainer.getSnapshot());
    int localIndex;
    int remoteIndex;
    LocalTransactionStatistics localTransactionStatistics = new LocalTransactionStatistics(false, TIME_SERVICE);
    localIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isLocal()) {
            localTransactionStatistics.addValue(stats, localIndex++);
        }
    }
    localTransactionStatistics.flushTo(globalContainer);
    snapshots.add(globalContainer.getSnapshot());
    localIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isLocal()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, (double) localIndex), stats, true);
            localIndex++;
        }
        if (stats.isRemote()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, 0D), stats, false);
        }
    }
    RemoteTransactionStatistics remoteTransactionStatistics = new RemoteTransactionStatistics(TIME_SERVICE);
    remoteIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isRemote()) {
            remoteTransactionStatistics.addValue(stats, remoteIndex++);
        }
    }
    remoteTransactionStatistics.flushTo(globalContainer);
    snapshots.add(globalContainer.getSnapshot());
    localIndex = 0;
    remoteIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isLocal()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, (double) localIndex, (double) localIndex), stats, true);
            localIndex++;
        }
        if (stats.isRemote()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, 0D, (double) remoteIndex), stats, false);
            remoteIndex++;
        }
    }
    assertFinalState(globalContainer);
}
Also used : ExtendedStatistic(org.infinispan.extendedstats.container.ExtendedStatistic) StatisticsSnapshot(org.infinispan.extendedstats.container.StatisticsSnapshot) ArrayList(java.util.ArrayList) ConcurrentGlobalContainer(org.infinispan.extendedstats.container.ConcurrentGlobalContainer)

Example 3 with ConcurrentGlobalContainer

use of org.infinispan.extendedstats.container.ConcurrentGlobalContainer in project infinispan by infinispan.

the class ConcurrentContainerTest method testIsolationWithEnqueueAndResetTransaction.

public void testIsolationWithEnqueueAndResetTransaction() {
    final ConcurrentGlobalContainer globalContainer = new ConcurrentGlobalContainer(TIME_SERVICE);
    final List<StatisticsSnapshot> snapshots = new ArrayList<>(4);
    snapshots.add(globalContainer.getSnapshot());
    int localIndex;
    int remoteIndex;
    LocalTransactionStatistics localTransactionStatistics = new LocalTransactionStatistics(false, TIME_SERVICE);
    RemoteTransactionStatistics remoteTransactionStatistics = new RemoteTransactionStatistics(TIME_SERVICE);
    localIndex = 0;
    remoteIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isLocal()) {
            localTransactionStatistics.addValue(stats, localIndex++);
        }
        if (stats.isRemote()) {
            remoteTransactionStatistics.addValue(stats, remoteIndex++);
        }
    }
    // all the stuff is enqueued
    globalContainer.flushing().set(true);
    localTransactionStatistics.flushTo(globalContainer);
    remoteTransactionStatistics.flushTo(globalContainer);
    localTransactionStatistics.flushTo(globalContainer);
    remoteTransactionStatistics.flushTo(globalContainer);
    localTransactionStatistics.flushTo(globalContainer);
    remoteTransactionStatistics.flushTo(globalContainer);
    Assert.assertEquals(globalContainer.queue().size(), 6);
    snapshots.add(globalContainer.getSnapshot());
    localIndex = 0;
    remoteIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isLocal()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, 0D), stats, true);
            localIndex++;
        }
        if (stats.isRemote()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, 0D), stats, false);
            remoteIndex++;
        }
    }
    globalContainer.flushing().set(false);
    // this should flush pending statistics
    snapshots.add(globalContainer.getSnapshot());
    localIndex = 0;
    remoteIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isLocal()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, 0D, 3D * localIndex), stats, true);
            localIndex++;
        }
        if (stats.isRemote()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, 0D, 3D * remoteIndex), stats, false);
            remoteIndex++;
        }
    }
    globalContainer.reset();
    snapshots.clear();
    snapshots.add(globalContainer.getSnapshot());
    localIndex = 0;
    remoteIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isLocal()) {
            assertSnapshotValues(snapshots, Collections.singletonList(0D), stats, true);
            localIndex++;
        }
        if (stats.isRemote()) {
            assertSnapshotValues(snapshots, Collections.singletonList(0D), stats, false);
            remoteIndex++;
        }
    }
    globalContainer.flushing().set(true);
    localTransactionStatistics.flushTo(globalContainer);
    remoteTransactionStatistics.flushTo(globalContainer);
    localTransactionStatistics.flushTo(globalContainer);
    remoteTransactionStatistics.flushTo(globalContainer);
    localTransactionStatistics.flushTo(globalContainer);
    globalContainer.reset();
    remoteTransactionStatistics.flushTo(globalContainer);
    snapshots.add(globalContainer.getSnapshot());
    Assert.assertTrue(globalContainer.isReset());
    Assert.assertEquals(globalContainer.queue().size(), 6);
    localIndex = 0;
    remoteIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isLocal()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, 0D), stats, true);
            localIndex++;
        }
        if (stats.isRemote()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, 0D), stats, false);
            remoteIndex++;
        }
    }
    globalContainer.flushing().set(false);
    snapshots.add(globalContainer.getSnapshot());
    Assert.assertFalse(globalContainer.isReset());
    localIndex = 0;
    remoteIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isLocal()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, 0D, 0D), stats, true);
            localIndex++;
        }
        if (stats.isRemote()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, 0D, 0D), stats, false);
            remoteIndex++;
        }
    }
    assertFinalState(globalContainer);
}
Also used : ExtendedStatistic(org.infinispan.extendedstats.container.ExtendedStatistic) StatisticsSnapshot(org.infinispan.extendedstats.container.StatisticsSnapshot) ArrayList(java.util.ArrayList) ConcurrentGlobalContainer(org.infinispan.extendedstats.container.ConcurrentGlobalContainer)

Example 4 with ConcurrentGlobalContainer

use of org.infinispan.extendedstats.container.ConcurrentGlobalContainer in project infinispan by infinispan.

the class ConcurrentContainerTest method testIsolationWithSingleActionMerge.

public void testIsolationWithSingleActionMerge() {
    final ConcurrentGlobalContainer globalContainer = new ConcurrentGlobalContainer(TIME_SERVICE);
    final List<StatisticsSnapshot> snapshots = new ArrayList<>(4);
    snapshots.add(globalContainer.getSnapshot());
    // two random stats, one local and one remote
    final ExtendedStatistic localStat = ExtendedStatistic.PREPARE_COMMAND_SIZE;
    final ExtendedStatistic remoteStat = ExtendedStatistic.NUM_COMMITTED_WR_TX;
    Assert.assertTrue(localStat.isLocal());
    Assert.assertTrue(remoteStat.isRemote());
    globalContainer.add(localStat, 10, true);
    snapshots.add(globalContainer.getSnapshot());
    assertSnapshotValues(snapshots, Arrays.asList(0D, 10D), localStat, true);
    assertSnapshotValues(snapshots, Arrays.asList(0D, 0D), remoteStat, false);
    globalContainer.add(remoteStat, 20, false);
    snapshots.add(globalContainer.getSnapshot());
    assertSnapshotValues(snapshots, Arrays.asList(0D, 10D, 10D), localStat, true);
    assertSnapshotValues(snapshots, Arrays.asList(0D, 0D, 20D), remoteStat, false);
    try {
        globalContainer.add(localStat, 30, false);
        fail("Expected exception");
    } catch (Exception e) {
    // expected
    }
    assertSnapshotValues(snapshots, Arrays.asList(0D, 10D, 10D), localStat, true);
    assertSnapshotValues(snapshots, Arrays.asList(0D, 0D, 20D), remoteStat, false);
    assertFinalState(globalContainer);
}
Also used : ExtendedStatistic(org.infinispan.extendedstats.container.ExtendedStatistic) StatisticsSnapshot(org.infinispan.extendedstats.container.StatisticsSnapshot) ArrayList(java.util.ArrayList) ConcurrentGlobalContainer(org.infinispan.extendedstats.container.ConcurrentGlobalContainer)

Example 5 with ConcurrentGlobalContainer

use of org.infinispan.extendedstats.container.ConcurrentGlobalContainer in project infinispan by infinispan.

the class ConcurrentContainerTest method testIsolationWithReset.

public void testIsolationWithReset() {
    final ConcurrentGlobalContainer globalContainer = new ConcurrentGlobalContainer(TIME_SERVICE);
    final List<StatisticsSnapshot> snapshots = new ArrayList<>(4);
    snapshots.add(globalContainer.getSnapshot());
    int localIndex;
    int remoteIndex;
    LocalTransactionStatistics localTransactionStatistics = new LocalTransactionStatistics(false, TIME_SERVICE);
    RemoteTransactionStatistics remoteTransactionStatistics = new RemoteTransactionStatistics(TIME_SERVICE);
    localIndex = 0;
    remoteIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isLocal()) {
            localTransactionStatistics.addValue(stats, localIndex++);
        }
        if (stats.isRemote()) {
            remoteTransactionStatistics.addValue(stats, remoteIndex++);
        }
    }
    localTransactionStatistics.flushTo(globalContainer);
    remoteTransactionStatistics.flushTo(globalContainer);
    snapshots.add(globalContainer.getSnapshot());
    localIndex = 0;
    remoteIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isLocal()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, (double) localIndex), stats, true);
            localIndex++;
        }
        if (stats.isRemote()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, (double) remoteIndex), stats, false);
            remoteIndex++;
        }
    }
    globalContainer.reset();
    snapshots.add(globalContainer.getSnapshot());
    localIndex = 0;
    remoteIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isLocal()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, (double) localIndex, 0D), stats, true);
            localIndex++;
        }
        if (stats.isRemote()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, (double) remoteIndex, 0D), stats, false);
            remoteIndex++;
        }
    }
    localTransactionStatistics.flushTo(globalContainer);
    remoteTransactionStatistics.flushTo(globalContainer);
    snapshots.add(globalContainer.getSnapshot());
    localIndex = 0;
    remoteIndex = 0;
    for (ExtendedStatistic stats : ExtendedStatistic.values()) {
        if (stats.isLocal()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, (double) localIndex, 0D, (double) localIndex), stats, true);
            localIndex++;
        }
        if (stats.isRemote()) {
            assertSnapshotValues(snapshots, Arrays.asList(0D, (double) remoteIndex, 0D, (double) remoteIndex), stats, false);
            remoteIndex++;
        }
    }
    assertFinalState(globalContainer);
}
Also used : ExtendedStatistic(org.infinispan.extendedstats.container.ExtendedStatistic) StatisticsSnapshot(org.infinispan.extendedstats.container.StatisticsSnapshot) ArrayList(java.util.ArrayList) ConcurrentGlobalContainer(org.infinispan.extendedstats.container.ConcurrentGlobalContainer)

Aggregations

ConcurrentGlobalContainer (org.infinispan.extendedstats.container.ConcurrentGlobalContainer)10 ArrayList (java.util.ArrayList)6 ExtendedStatistic (org.infinispan.extendedstats.container.ExtendedStatistic)6 StatisticsSnapshot (org.infinispan.extendedstats.container.StatisticsSnapshot)6 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 CacheStatisticCollector (org.infinispan.extendedstats.CacheStatisticCollector)3 CacheStatisticManager (org.infinispan.extendedstats.CacheStatisticManager)3 ExtendedStatisticInterceptor (org.infinispan.extendedstats.wrappers.ExtendedStatisticInterceptor)3 ExtendedStatisticRpcManager (org.infinispan.extendedstats.wrappers.ExtendedStatisticRpcManager)3 RpcManager (org.infinispan.remoting.rpc.RpcManager)3 ExtendedStatisticLockManager (org.infinispan.extendedstats.wrappers.ExtendedStatisticLockManager)2 TestingUtil.extractLockManager (org.infinispan.test.TestingUtil.extractLockManager)2 ControlledRpcManager (org.infinispan.util.ControlledRpcManager)2 ReplicatedControlledConsistentHashFactory (org.infinispan.util.ReplicatedControlledConsistentHashFactory)2 WithinThreadExecutor (org.infinispan.util.concurrent.WithinThreadExecutor)2 LockManager (org.infinispan.util.concurrent.locks.LockManager)2 LockContainer (org.infinispan.util.concurrent.locks.impl.LockContainer)2