Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void setUpgradeTransactionMustBeAtomic() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SetUpgradeTransactionMustBeAtomic()
        {
            using (MetaDataStore store = NewMetaDataStore())
            {
                PagedFile pf = store.PagedFile;
                store.SetUpgradeTransaction(0, 0, 0);
                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);
                // writers
                race.AddContestants(3, () =>
                {
                    long count = writeCount.incrementAndGet();
                    store.SetUpgradeTransaction(count, count, count);
                });

                // file readers
                race.AddContestants(3, throwing(() =>
                {
                    using (PageCursor cursor = pf.Io(0, PagedFile.PF_SHARED_READ_LOCK))
                    {
                        assertTrue(cursor.next());
                        long id;
                        long checksum;
                        do
                        {
                            id       = store.GetRecordValue(cursor, MetaDataStore.Position.UpgradeTransactionId);
                            checksum = store.GetRecordValue(cursor, MetaDataStore.Position.UpgradeTransactionChecksum);
                        } while (cursor.shouldRetry());
                        AssertIdEqualsChecksum(id, checksum, "file");
                        fileReadCount.incrementAndGet();
                    }
                }));

                race.AddContestants(3, () =>
                {
                    TransactionId transaction = store.UpgradeTransaction;
                    AssertIdEqualsChecksum(transaction.TransactionIdConflict(), transaction.Checksum(), "API");
                    apiReadCount.incrementAndGet();
                });
                race.Go();
            }
        }
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();
            }
        }