public void LockIsKeptAlive_Failure()
        {
            var config = new RemoteLockerTesterConfig
            {
                LockersCount           = 2,
                LocalRivalOptimization = LocalRivalOptimization.Disabled,
                LockTtl                         = TimeSpan.FromSeconds(5),
                LockMetadataTtl                 = TimeSpan.FromMinutes(1),
                KeepLockAliveInterval           = TimeSpan.FromSeconds(10),
                ChangeLockRowThreshold          = 10,
                TimestampProviderStochasticType = TimestampProviderStochasticType.None,
                CassandraClusterSettings        = SingleCassandraNodeSetUpFixture.CreateCassandraClusterSettings(attempts: 1, timeout: TimeSpan.FromSeconds(1)),
            };

            using (var tester = new RemoteLockerTester(config))
            {
                var lockId = Guid.NewGuid().ToString();
                var lock1  = tester[0].Lock(lockId);
                Thread.Sleep(TimeSpan.FromSeconds(3));
                Assert.That(tester[1].TryGetLock(lockId, out var lock2), Is.False);
                Thread.Sleep(TimeSpan.FromSeconds(4)); // waiting in total: 3 + 4 = 1*1 + 5 + 1 sec
                Assert.That(tester[1].TryGetLock(lockId, out lock2), Is.True);
                lock2.Dispose();
                lock1.Dispose();
            }
        }
        public void LockCancellationToken_IsCancelled_AfterLosingLock()
        {
            var config = new RemoteLockerTesterConfig
            {
                LockersCount           = 1,
                LocalRivalOptimization = LocalRivalOptimization.Disabled,
                LockTtl                         = TimeSpan.FromSeconds(5),
                LockMetadataTtl                 = TimeSpan.FromMinutes(1),
                KeepLockAliveInterval           = TimeSpan.FromSeconds(3),
                ChangeLockRowThreshold          = 10,
                TimestampProviderStochasticType = TimestampProviderStochasticType.None,
                CassandraClusterSettings        = SingleCassandraNodeSetUpFixture.CreateCassandraClusterSettings(attempts: 1, timeout: TimeSpan.FromSeconds(1)),
            };

            using (var tester = new RemoteLockerTester(config))
            {
                var lockId = Guid.NewGuid().ToString();
                using (var lock1 = tester[0].Lock(lockId))
                {
                    Assert.That(lock1.LockAliveToken.IsCancellationRequested, Is.False);

                    // waiting more than LockTtl * 0.5 with no lock prolongation
                    Thread.Sleep(config.KeepLockAliveInterval);

                    Assert.That(lock1.LockAliveToken.IsCancellationRequested, Is.True);
                }
            }
        }
예제 #3
0
        public void OneTimeSetUp()
        {
            var serializer       = new Serializer(new AllPropertiesExtractor(), null, GroBufOptions.MergeOnRead);
            var cassandraCluster = new CassandraCluster(SingleCassandraNodeSetUpFixture.CreateCassandraClusterSettings(), logger);
            var settings         = new CassandraRemoteLockImplementationSettings(new DefaultTimestampProvider(), SingleCassandraNodeSetUpFixture.RemoteLockKeyspace, SingleCassandraNodeSetUpFixture.RemoteLockColumnFamily, TimeSpan.FromMinutes(3), TimeSpan.FromDays(30), TimeSpan.FromSeconds(5), 10);

            remoteLockImplementation = new CassandraRemoteLockImplementation(cassandraCluster, serializer, settings);
        }
 public static RemoteLockerTesterConfig Default()
 {
     return(new RemoteLockerTesterConfig
     {
         LockersCount = 1,
         LocalRivalOptimization = LocalRivalOptimization.Enabled,
         LockTtl = TimeSpan.FromSeconds(10),
         LockMetadataTtl = TimeSpan.FromMinutes(1),
         KeepLockAliveInterval = TimeSpan.FromSeconds(2),
         ChangeLockRowThreshold = 10,
         TimestampProviderStochasticType = TimestampProviderStochasticType.None,
         CassandraClusterSettings = SingleCassandraNodeSetUpFixture.CreateCassandraClusterSettings(),
         CassandraFailProbability = null,
     });
 }
예제 #5
0
 public void SmallTtl(int locks, int threads, int operationsPerThread, TimestampProviderStochasticType stochasticType)
 {
     DoTest(new TestConfig
     {
         Locks = locks,
         OperationsPerThread      = operationsPerThread,
         FastRunningOpProbability = 1.00d,
         LongRunningOpProbability = 0.00d,
         SyncInterval             = null,
         TesterConfig             = new RemoteLockerTesterConfig
         {
             LockersCount           = threads,
             LocalRivalOptimization = LocalRivalOptimization.Disabled,
             LockTtl                         = TimeSpan.FromMilliseconds(2000),
             LockMetadataTtl                 = TimeSpan.FromSeconds(10),
             KeepLockAliveInterval           = TimeSpan.FromMilliseconds(50),
             ChangeLockRowThreshold          = int.MaxValue,
             TimestampProviderStochasticType = stochasticType,
             CassandraClusterSettings        = SingleCassandraNodeSetUpFixture.CreateCassandraClusterSettings(attempts: 1, timeout: TimeSpan.FromMilliseconds(350)),
             CassandraFailProbability        = null
         },
     });
 }
예제 #6
0
 public void Normal(int locks, int threads, int operationsPerThread, double longRunningOpProbability, LocalRivalOptimization localRivalOptimization, int?syncIntervalInSeconds)
 {
     DoTest(new TestConfig
     {
         Locks = locks,
         LongRunningOpProbability = longRunningOpProbability,
         OperationsPerThread      = operationsPerThread,
         FastRunningOpProbability = 0.2d,
         SyncInterval             = syncIntervalInSeconds.HasValue ? TimeSpan.FromSeconds(syncIntervalInSeconds.Value) : (TimeSpan?)null,
         TesterConfig             = new RemoteLockerTesterConfig
         {
             LockersCount           = threads,
             LocalRivalOptimization = localRivalOptimization,
             LockTtl                         = TimeSpan.FromSeconds(3),
             LockMetadataTtl                 = TimeSpan.FromSeconds(10),
             KeepLockAliveInterval           = TimeSpan.FromSeconds(1),
             ChangeLockRowThreshold          = 10,
             TimestampProviderStochasticType = TimestampProviderStochasticType.None,
             CassandraClusterSettings        = SingleCassandraNodeSetUpFixture.CreateCassandraClusterSettings(attempts: 1, timeout: TimeSpan.FromSeconds(1)),
             CassandraFailProbability        = null
         },
     });
 }
예제 #7
0
 public void SetUp()
 {
     SingleCassandraNodeSetUpFixture.TruncateAllColumnFamilies();
 }
예제 #8
0
        public RemoteLockerTester(RemoteLockerTesterConfig config = null)
        {
            config = config ?? RemoteLockerTesterConfig.Default();
            var localRivalOptimizationIsEnabled = config.LocalRivalOptimization != LocalRivalOptimization.Disabled;
            var serializer = new Serializer(new AllPropertiesExtractor(), null, GroBufOptions.MergeOnRead);
            ICassandraCluster cassandraCluster = new CassandraCluster(config.CassandraClusterSettings, logger);

            if (config.CassandraFailProbability.HasValue)
            {
                cassandraCluster = new FailedCassandraCluster(cassandraCluster, config.CassandraFailProbability.Value);
            }
            var timestampProvider                 = new StochasticTimestampProvider(config.TimestampProviderStochasticType, config.LockTtl);
            var implementationSettings            = new CassandraRemoteLockImplementationSettings(timestampProvider, SingleCassandraNodeSetUpFixture.RemoteLockKeyspace, SingleCassandraNodeSetUpFixture.RemoteLockColumnFamily, config.LockTtl, config.LockMetadataTtl, config.KeepLockAliveInterval, config.ChangeLockRowThreshold);
            var cassandraRemoteLockImplementation = new CassandraRemoteLockImplementation(cassandraCluster, serializer, implementationSettings);

            remoteLockers       = new RemoteLocker[config.LockersCount];
            remoteLockerMetrics = new RemoteLockerMetrics("dummyKeyspace");
            if (localRivalOptimizationIsEnabled)
            {
                var remoteLocker = new RemoteLocker(cassandraRemoteLockImplementation, remoteLockerMetrics, logger);
                for (var i = 0; i < config.LockersCount; i++)
                {
                    remoteLockers[i] = remoteLocker;
                }
            }
            else
            {
                for (var i = 0; i < config.LockersCount; i++)
                {
                    remoteLockers[i] = new RemoteLocker(new CassandraRemoteLockImplementation(cassandraCluster, serializer, implementationSettings), remoteLockerMetrics, logger);
                }
            }
            // it is important to use another CassandraCluster (with another setting of attempts, for example)
            cassandraRemoteLockImplementationForCheckings = new CassandraRemoteLockImplementation(new CassandraCluster(SingleCassandraNodeSetUpFixture.CreateCassandraClusterSettings(), logger), serializer, implementationSettings);
        }