コード例 #1
0
        /// <summary>
        /// Tests failover scenario when lock owner node leaves.
        /// </summary>
        private static IIgniteLock TestFailover(bool isFailoverSafe)
        {
            var ignite = Ignition.Start(TestUtils.GetTestConfiguration());

            var cfg = new LockConfiguration
            {
                Name           = TestUtils.TestName,
                IsFailoverSafe = isFailoverSafe
            };

            var lock1 = ignite.GetOrCreateLock(cfg, true);
            var evt   = new ManualResetEventSlim(false);

            Task.Factory.StartNew(() =>
            {
                var igniteCfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
                {
                    IgniteInstanceName = cfg.Name
                };

                var ignite2 = Ignition.Start(igniteCfg);

                var lock2 = ignite2.GetOrCreateLock(cfg, true);
                lock2.Enter();

                evt.Set();
                Thread.Sleep(100);

                Ignition.Stop(cfg.Name, true);
            });

            evt.Wait();

            return(lock1);
        }
コード例 #2
0
ファイル: IgniteLockTests.cs プロジェクト: zyling10/ignite
        public void TestLockConfigurationCantBeModifiedAfterLockCreation()
        {
            var cfg = new LockConfiguration
            {
                Name           = TestUtils.TestName,
                IsFair         = true,
                IsFailoverSafe = true
            };

            var lck = Ignite.GetOrCreateLock(cfg, true);

            // Change original instance.
            cfg.Name           = "y";
            cfg.IsFair         = false;
            cfg.IsFailoverSafe = false;

            // Change returned instance.
            lck.Configuration.Name           = "y";
            lck.Configuration.IsFair         = false;
            lck.Configuration.IsFailoverSafe = false;

            // Verify: actual config has not changed.
            Assert.AreEqual(TestUtils.TestName, lck.Configuration.Name);
            Assert.IsTrue(lck.Configuration.IsFair);
            Assert.IsTrue(lck.Configuration.IsFailoverSafe);
        }
コード例 #3
0
ファイル: IgniteLock.cs プロジェクト: pks-os/gridgain
        /// <summary>
        /// Initializes a new instance of <see cref="IgniteLock"/>.
        /// </summary>
        public IgniteLock(IPlatformTargetInternal target, LockConfiguration cfg)
            : base(target)
        {
            Debug.Assert(cfg != null);

            _cfg = cfg;
        }
コード例 #4
0
        public void ReceivingNativeInput_WhenHooked_CallsFactoryWithReceivedInput()
        {
            // Arrange
            Action <NativeKeyboardInput> nativeInputCallback = null;

            _nativeKeyboardHookServiceMock.Setup(f => f.Hook(It.IsAny <Action <NativeKeyboardInput> >())).Callback <Action <NativeKeyboardInput> >(a => nativeInputCallback = a);
            _keyboardInputFactoryMock.Setup(f => f.Create(It.IsAny <NativeKeyboardInput>()));

            var keyboardInput = new KeyboardInput(
                KeyboardInputKey.A,
                KeyboardInputDirection.KeyDown,
                new KeyboardInputLocks(false, false, false),
                new KeyboardInputModifiers(!false, false, false));

            _keyboardInputFactoryMock.Setup(f => f.Create(It.IsAny <NativeKeyboardInput>())).Returns(keyboardInput);

            var keyboardEventConfiguration = new KeyboardEventConfiguration(
                new KeyboardInputKeyConfiguration(KeyboardInputKey.AllKeys.ToArray()),
                ModifierConfiguration.CreateNotApplicable(),
                LockConfiguration.CreateNotApplicable());

            _receiverMock.Setup(f => f.ReceiveAsync(It.IsAny <KeyboardInput>())).Returns(Task.FromResult(true));
            _receiverMock.Setup(f => f.Configuration).Returns(keyboardEventConfiguration);
            _sut.HookKeyboard();

            var nativeKeyboardInput = new NativeKeyboardInput(Keys.A, NativeKeyboardInputDirection.KeyDown);

            // Act
            nativeInputCallback(nativeKeyboardInput);

            // Assert
            _keyboardInputFactoryMock.Verify(f => f.Create(nativeKeyboardInput), Times.Once);
        }
コード例 #5
0
        private void Reset()
        {
            m_collider  = GetComponent <Collider>();
            m_rigidbody = GetComponent <Rigidbody>();

            m_movementConfig = new MovementConfiguration().GetDefault();
            m_lockConfig     = new LockConfiguration().GetDefault();
            m_possessConfig  = new PossessConfiguration().GetDefault();
        }
コード例 #6
0
ファイル: Ignite.cs プロジェクト: zhaoshiling1017/ignite
        /** <inheritdoc /> */
        public IIgniteLock GetOrCreateLock(string name)
        {
            IgniteArgumentCheck.NotNullOrEmpty(name, "name");

            var configuration = new LockConfiguration
            {
                Name = name
            };

            return(GetOrCreateLock(configuration, true));
        }
コード例 #7
0
ファイル: IgniteLockTests.cs プロジェクト: zyling10/ignite
        public void TestFairLockGuaranteesOrder()
        {
            const int count = 20;

            var cfg = new LockConfiguration
            {
                Name           = TestUtils.TestName,
                IsFair         = true,
                IsFailoverSafe = true
            };

            var lck = Ignite.GetOrCreateLock(cfg, true);

            lck.Enter();

            var locks   = new ConcurrentQueue <int>();
            var threads = new Thread[count];

            var evt = new AutoResetEvent(false);

            for (int i = 0; i < count; i++)
            {
                var id = i;

                var thread = new Thread(() =>
                {
                    evt.Set();
                    lck.Enter();
                    locks.Enqueue(id);
                    lck.Exit();
                });

                thread.Start();

                evt.WaitOne();

                Thread.Sleep(100);

                threads[i] = thread;
            }

            lck.Exit();

            foreach (var thread in threads)
            {
                thread.Join();
            }

            Assert.AreEqual(count, locks.Count);
            CollectionAssert.IsOrdered(locks);
        }
コード例 #8
0
        public TestRegistrationService()
        {
            ForKeyboardInput <TestKeyboardReceiver>(
                () => new KeyboardEventConfiguration(
                    new KeyboardInputKeyConfiguration(KeyboardInputKey.A),
                    new ModifierConfiguration(false, false, false),
                    LockConfiguration.CreateNotApplicable()));

            ForKeyboardInput <Test2KeyboardReceiver>(
                () => new KeyboardEventConfiguration(
                    new KeyboardInputKeyConfiguration(KeyboardInputKey.AllKeys.ToArray()),
                    new ModifierConfiguration(true, false, false),
                    new LockConfiguration(false, false, true)));

            ForMouseInput <TestMouseReceiver>(
                () => new MouseEventConfiguration(MouseInputKey.Right, MouseInputDirection.MouseDown));
        }
コード例 #9
0
ファイル: Ignite.cs プロジェクト: zhaoshiling1017/ignite
        /** <inheritdoc /> */
        public IIgniteLock GetOrCreateLock(LockConfiguration configuration, bool create)
        {
            IgniteArgumentCheck.NotNull(configuration, "configuration");
            IgniteArgumentCheck.NotNullOrEmpty(configuration.Name, "configuration.Name");

            // Create a copy to ignore modifications from outside.
            var cfg = new LockConfiguration(configuration);

            var target = DoOutOpObject((int)Op.GetOrCreateLock, w =>
            {
                w.WriteString(configuration.Name);
                w.WriteBoolean(configuration.IsFailoverSafe);
                w.WriteBoolean(configuration.IsFair);
                w.WriteBoolean(create);
            });

            return(target == null ? null : new IgniteLock(target, cfg));
        }
コード例 #10
0
ファイル: IgniteLockTests.cs プロジェクト: zyling10/ignite
        public void TestEnteredLockThrowsOnRemove()
        {
            var cfg = new LockConfiguration
            {
                Name = TestUtils.TestName
            };

            var lck = Ignite.GetOrCreateLock(cfg, true);

            lck.Enter();
            Assert.IsTrue(lck.IsEntered());

            var ex = Assert.Throws <IgniteException>(() => lck.Remove());

            StringAssert.StartsWith("Failed to remove reentrant lock with blocked threads", ex.Message);

            lck.Exit();
            lck.Remove();

            Assert.IsNull(Ignite.GetOrCreateLock(cfg, false));
        }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of <see cref="LockConfiguration"/> class.
 /// </summary>
 /// <param name="other">Other configuration to copy.</param>
 public LockConfiguration(LockConfiguration other)
 {
     Name           = other.Name;
     IsFair         = other.IsFair;
     IsFailoverSafe = other.IsFailoverSafe;
 }