Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDeferAllLocks()
        public virtual void ShouldDeferAllLocks()
        {
            // GIVEN
            TestLocks           actualLocks  = new TestLocks();
            TestLocksClient     actualClient = actualLocks.NewClient();
            DeferringLockClient client       = new DeferringLockClient(actualClient);

            // WHEN
            ISet <LockUnit> expected = new HashSet <LockUnit>();

            ResourceType[] types = ResourceTypes.values();
            for (int i = 0; i < 10_000; i++)
            {
                bool     exclusive = Random.nextBoolean();
                LockUnit lockUnit  = new LockUnit(Random.among(types), abs(Random.nextLong()), exclusive);

                if (exclusive)
                {
                    client.AcquireExclusive(LockTracer.NONE, lockUnit.ResourceType(), lockUnit.ResourceId());
                }
                else
                {
                    client.AcquireShared(LockTracer.NONE, lockUnit.ResourceType(), lockUnit.ResourceId());
                }
                expected.Add(lockUnit);
            }
            actualClient.AssertRegisteredLocks(Collections.emptySet());
            client.AcquireDeferredLocks(LockTracer.NONE);

            // THEN
            actualClient.AssertRegisteredLocks(expected);
        }
Exemple #2
0
        private void AddLock(ResourceType resourceType, long resourceId, bool exclusive)
        {
            LockUnit   lockUnit  = new LockUnit(resourceType, resourceId, exclusive);
            MutableInt lockCount = _locks.computeIfAbsent(lockUnit, k => new MutableInt());

            lockCount.increment();
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void exclusiveOrderedByResourceTypes()
        public virtual void ExclusiveOrderedByResourceTypes()
        {
            LockUnit unit1 = new LockUnit(ResourceTypes.Node, 1, true);
            LockUnit unit2 = new LockUnit(ResourceTypes.Relationship, 1, true);
            LockUnit unit3 = new LockUnit(ResourceTypes.Node, 2, true);
            LockUnit unit4 = new LockUnit(ResourceTypes.RelationshipType, 1, true);
            LockUnit unit5 = new LockUnit(ResourceTypes.Relationship, 2, true);

            IList <LockUnit> list = new IList <LockUnit> {
                unit1, unit2, unit3, unit4, unit5
            };

            list.Sort();

            assertEquals(asList(unit1, unit3, unit2, unit5, unit4), list);
        }
Exemple #4
0
        private void RemoveLock(ResourceType resourceType, long resourceId, bool exclusive)
        {
            LockUnit   lockUnit  = new LockUnit(resourceType, resourceId, exclusive);
            MutableInt lockCount = _locks[lockUnit];

            if (lockCount == null)
            {
                throw new System.InvalidOperationException("Cannot release " + (exclusive ? "exclusive" : "shared") + " lock that it " + "does not hold: " + resourceType + "[" + resourceId + "].");
            }

            lockCount.decrement();

            if (lockCount.intValue() == 0)
            {
                _locks.Remove(lockUnit);
            }
        }