Beispiel #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);
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void acquireBothSharedAndExclusiveLockThenReleaseExclusive()
        public virtual void AcquireBothSharedAndExclusiveLockThenReleaseExclusive()
        {
            // GIVEN
            TestLocks           actualLocks  = new TestLocks();
            TestLocksClient     actualClient = actualLocks.NewClient();
            DeferringLockClient client       = new DeferringLockClient(actualClient);

            client.AcquireShared(LockTracer.NONE, ResourceTypes.Node, 1);
            client.AcquireExclusive(LockTracer.NONE, ResourceTypes.Node, 1);
            client.ReleaseExclusive(ResourceTypes.Node, 1);

            // WHEN
            client.AcquireDeferredLocks(LockTracer.NONE);

            // THEN
            actualClient.AssertRegisteredLocks(Collections.singleton(new LockUnit(ResourceTypes.Node, 1, false)));
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void sharedLockAcquiredMultipleTimesCanNotBeReleasedAtOnce()
        public virtual void SharedLockAcquiredMultipleTimesCanNotBeReleasedAtOnce()
        {
            // GIVEN
            TestLocks           actualLocks  = new TestLocks();
            TestLocksClient     actualClient = actualLocks.NewClient();
            DeferringLockClient client       = new DeferringLockClient(actualClient);

            client.AcquireShared(LockTracer.NONE, ResourceTypes.Node, 1);
            client.AcquireShared(LockTracer.NONE, ResourceTypes.Node, 1);
            client.ReleaseShared(ResourceTypes.Node, 1);

            // WHEN
            client.AcquireDeferredLocks(LockTracer.NONE);

            // THEN
            actualClient.AssertRegisteredLocks(Collections.singleton(new LockUnit(ResourceTypes.Node, 1, false)));
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void releaseOfNotHeldExclusiveLockThrows()
        public virtual void ReleaseOfNotHeldExclusiveLockThrows()
        {
            // GIVEN
            TestLocks           actualLocks  = new TestLocks();
            TestLocksClient     actualClient = actualLocks.NewClient();
            DeferringLockClient client       = new DeferringLockClient(actualClient);

            try
            {
                // WHEN
                client.ReleaseExclusive(ResourceTypes.Node, 42);
                fail("Exception expected");
            }
            catch (Exception e)
            {
                // THEN
                assertThat(e, instanceOf(typeof(System.InvalidOperationException)));
            }
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void exclusiveLocksAcquiredFirst()
        public virtual void ExclusiveLocksAcquiredFirst()
        {
            // GIVEN
            TestLocks           actualLocks  = new TestLocks();
            TestLocksClient     actualClient = actualLocks.NewClient();
            DeferringLockClient client       = new DeferringLockClient(actualClient);

            client.AcquireShared(LockTracer.NONE, ResourceTypes.Node, 1);
            client.AcquireExclusive(LockTracer.NONE, ResourceTypes.Node, 2);
            client.AcquireExclusive(LockTracer.NONE, ResourceTypes.Node, 3);
            client.AcquireExclusive(LockTracer.NONE, ResourceTypes.Relationship, 1);
            client.AcquireShared(LockTracer.NONE, ResourceTypes.Relationship, 2);
            client.AcquireShared(LockTracer.NONE, ResourceTypes.Label, 1);
            client.AcquireExclusive(LockTracer.NONE, ResourceTypes.Node, 42);

            // WHEN
            client.AcquireDeferredLocks(LockTracer.NONE);

            // THEN
            ISet <LockUnit> expectedLocks = new LinkedHashSet <LockUnit>(Arrays.asList(new LockUnit(ResourceTypes.Node, 2, true), new LockUnit(ResourceTypes.Node, 3, true), new LockUnit(ResourceTypes.Node, 42, true), new LockUnit(ResourceTypes.Relationship, 1, true), new LockUnit(ResourceTypes.Node, 1, false), new LockUnit(ResourceTypes.Relationship, 2, false), new LockUnit(ResourceTypes.Label, 1, false)));

            actualClient.AssertRegisteredLocks(expectedLocks);
        }