Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyUpdateResults(int filePages, PagedFile pagedFile, java.util.List<java.util.concurrent.Future<UpdateResult>> futures) throws InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
        private void VerifyUpdateResults(int filePages, PagedFile pagedFile, IList <Future <UpdateResult> > futures)
        {
            UpdateResult[] results = new UpdateResult[futures.Count];
            for (int i = 0; i < results.Length; i++)
            {
                results[i] = futures[i].get();
            }
            foreach (UpdateResult result in results)
            {
                using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_READ_LOCK))
                {
                    for (int i = 0; i < filePages; i++)
                    {
                        assertTrue(cursor.Next());

                        int threadId      = result.ThreadId;
                        int expectedCount = result.PageCounts[i];
                        int actualCount;
                        do
                        {
                            cursor.Offset = threadId * 4;
                            actualCount   = cursor.Int;
                        } while (cursor.ShouldRetry());

                        assertThat("wrong count for threadId:" + threadId + ", aka. real threadId:" + result.RealThreadId + ", filePageId:" + i, actualCount, @is(expectedCount));
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Verifies the records on the current page of the cursor.
        /// <para>
        /// This does the do-while-retry loop internally.
        /// </para>
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void verifyRecordsMatchExpected(PageCursor cursor) throws java.io.IOException
        protected internal virtual void VerifyRecordsMatchExpected(PageCursor cursor)
        {
            ByteBuffer expectedPageContents = ByteBuffer.allocate(FilePageSize);
            ByteBuffer actualPageContents   = ByteBuffer.allocate(FilePageSize);

            sbyte[] record = new sbyte[RecordSize];
            long    pageId = cursor.CurrentPageId;

            for (int i = 0; i < RecordsPerFilePage; i++)
            {
                long recordId = (pageId * RecordsPerFilePage) + i;
                expectedPageContents.position(RecordSize * i);
                ByteBuffer slice = expectedPageContents.slice();
                slice.limit(RecordSize);
                GenerateRecordForId(recordId, slice);
                do
                {
                    cursor.Offset = RecordSize * i;
                    cursor.GetBytes(record);
                } while (cursor.ShouldRetry());
                actualPageContents.position(RecordSize * i);
                actualPageContents.put(record);
            }
            AssertRecords(pageId, actualPageContents, expectedPageContents);
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void readAndVerifyAdversarialPage(PageCursor cursor, int pageSize) throws java.io.IOException
        private void ReadAndVerifyAdversarialPage(PageCursor cursor, int pageSize)
        {
            sbyte[] actualPage   = new sbyte[pageSize];
            sbyte[] expectedPage = new sbyte[pageSize];
            do
            {
                cursor.GetBytes(actualPage);
            } while (cursor.ShouldRetry());
            Arrays.fill(expectedPage, actualPage[0]);
            string msg = string.Format("filePageId = {0}, pageSize = {1}", cursor.CurrentPageId, pageSize);

            assertThat(msg, actualPage, byteArray(expectedPage));
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void performConsistentAdversarialWrite(PageCursor cursor, java.util.concurrent.ThreadLocalRandom rng, int pageSize) throws java.io.IOException
        private void PerformConsistentAdversarialWrite(PageCursor cursor, ThreadLocalRandom rng, int pageSize)
        {
            for (int j = 0; j < 3; j++)
            {
                assertTrue(cursor.Next());
                // Avoid generating zeros, so we can tell them apart from the
                // absence of a write:
                sbyte b = ( sbyte )rng.Next(1, 127);
                for (int k = 0; k < pageSize; k++)
                {
                    cursor.PutByte(b);
                }
                assertFalse(cursor.ShouldRetry());
            }
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void performReadOrUpdate(java.util.concurrent.ThreadLocalRandom rng, boolean updateCounter, int pf_flags) throws java.io.IOException
            protected internal override void performReadOrUpdate(ThreadLocalRandom rng, bool updateCounter, int pfFlags)
            {
                try
                {
                    int   pageCount = rng.Next(1, _maxCursorsPerThread);
                    int[] pageIds   = new int[pageCount];
                    for (int j = 0; j < pageCount; j++)
                    {
                        pageIds[j] = rng.Next(0, _filePages);
                    }
                    PageCursor[] cursors = new PageCursor[pageCount];
                    for (int j = 0; j < pageCount; j++)
                    {
                        cursors[j] = _pagedFile.io(pageIds[j], pfFlags);
                        assertTrue(cursors[j].Next());
                    }
                    for (int j = 0; j < pageCount; j++)
                    {
                        int        pageId = pageIds[j];
                        PageCursor cursor = cursors[j];
                        int        counter;
                        do
                        {
                            cursor.Offset = offset;
                            counter       = cursor.Int;
                        } while (cursor.ShouldRetry());
                        string lockName = updateCounter ? "PF_SHARED_WRITE_LOCK" : "PF_SHARED_READ_LOCK";
                        string reason   = string.Format("inconsistent page read from filePageId = {0}, with {1}, workerId = {2} [t:{3}]", pageId, lockName, threadId, Thread.CurrentThread.Id);
                        assertThat(reason, counter, @is(pageCounts[pageId]));
                        if (updateCounter)
                        {
                            counter++;
                            pageCounts[pageId]++;
                            cursor.Offset = offset;
                            cursor.PutInt(counter);
                        }
                    }
                    foreach (PageCursor cursor in cursors)
                    {
                        cursor.Close();
                    }
                }
                catch (Exception throwable)
                {
                    _shouldStop.set(true);
                    throw throwable;
                }
            }
Esempio n. 6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void performReadOrUpdate(java.util.concurrent.ThreadLocalRandom rng, boolean updateCounter, int pf_flags) throws java.io.IOException
            protected internal override void performReadOrUpdate(ThreadLocalRandom rng, bool updateCounter, int pfFlags)
            {
                int pageId = rng.Next(0, _filePages);

                using (PageCursor cursor = _pagedFile.io(pageId, pfFlags))
                {
                    int counter;
                    try
                    {
                        assertTrue(cursor.Next());
                        do
                        {
                            cursor.Offset = offset;
                            counter       = cursor.Int;
                        } while (cursor.ShouldRetry());
                        string lockName = updateCounter ? "PF_SHARED_WRITE_LOCK" : "PF_SHARED_READ_LOCK";
                        string reason   = string.Format("inconsistent page read from filePageId:{0}, with {1}, threadId:{2}", pageId, lockName, Thread.CurrentThread.Id);
                        assertThat(reason, counter, @is(pageCounts[pageId]));
                    }
                    catch (Exception throwable)
                    {
                        _shouldStop.set(true);
                        throw throwable;
                    }
                    if (updateCounter)
                    {
                        counter++;
                        pageCounts[pageId]++;
                        cursor.Offset = offset;
                        cursor.PutInt(counter);
                    }
                    if (cursor.CheckAndClearBoundsFlag())
                    {
                        _shouldStop.set(true);
                        throw new System.IndexOutOfRangeException("offset = " + offset + ", filPageId:" + pageId + ", threadId: " + threadId + ", updateCounter = " + updateCounter);
                    }
                }
            }