Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testRecordTransactionClosed()
        public virtual void TestRecordTransactionClosed()
        {
            // GIVEN
            MetaDataStore metaDataStore = NewMetaDataStore();

            long[] originalClosedTransaction = metaDataStore.LastClosedTransaction;
            long   transactionId             = originalClosedTransaction[0] + 1;
            long   version    = 1L;
            long   byteOffset = 777L;

            // WHEN
            metaDataStore.TransactionClosed(transactionId, version, byteOffset);
            // long[] with the highest offered gap-free number and its meta data.
            long[] closedTransactionFlags = metaDataStore.LastClosedTransaction;

            //EXPECT
            assertEquals(version, closedTransactionFlags[1]);
            assertEquals(byteOffset, closedTransactionFlags[2]);

            // WHEN
            metaDataStore.Close();
            metaDataStore = NewMetaDataStore();

            // EXPECT
            long[] lastClosedTransactionFlags = metaDataStore.LastClosedTransaction;
            assertEquals(version, lastClosedTransactionFlags[1]);
            assertEquals(byteOffset, lastClosedTransactionFlags[2]);

            metaDataStore.Close();
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void transactionClosedMustBeAtomic() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TransactionClosedMustBeAtomic()
        {
            using (MetaDataStore store = NewMetaDataStore())
            {
                PagedFile pf           = store.PagedFile;
                int       initialValue = 2;
                store.TransactionClosed(initialValue, initialValue, initialValue);
                AtomicLong writeCount    = new AtomicLong();
                AtomicLong fileReadCount = new AtomicLong();
                AtomicLong apiReadCount  = new AtomicLong();
                int        upperLimit    = 10_000;
                int        lowerLimit    = 100;
                long       endTime       = currentTimeMillis() + SECONDS.toMillis(10);

                Race race = new Race();
                race.WithEndCondition(() => writeCount.get() >= upperLimit && fileReadCount.get() >= upperLimit && apiReadCount.get() >= upperLimit);
                race.WithEndCondition(() => writeCount.get() >= lowerLimit && fileReadCount.get() >= lowerLimit && apiReadCount.get() >= lowerLimit && currentTimeMillis() >= endTime);
                race.AddContestants(3, () =>
                {
                    long count = writeCount.incrementAndGet();
                    store.TransactionCommitted(count, count, count);
                });

                race.AddContestants(3, throwing(() =>
                {
                    using (PageCursor cursor = pf.Io(0, PagedFile.PF_SHARED_READ_LOCK))
                    {
                        assertTrue(cursor.next());
                        long logVersion;
                        long byteOffset;
                        do
                        {
                            logVersion = store.GetRecordValue(cursor, MetaDataStore.Position.LastClosedTransactionLogVersion);
                            byteOffset = store.GetRecordValue(cursor, MetaDataStore.Position.LastClosedTransactionLogByteOffset);
                        } while (cursor.shouldRetry());
                        AssertLogVersionEqualsByteOffset(logVersion, byteOffset, "file");
                        fileReadCount.incrementAndGet();
                    }
                }));

                race.AddContestants(3, () =>
                {
                    long[] transaction = store.LastClosedTransaction;
                    AssertLogVersionEqualsByteOffset(transaction[0], transaction[1], "API");
                    apiReadCount.incrementAndGet();
                });
                race.Go();
            }
        }