⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t_filesystemdata.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                long cid1 =                     t.addContainer(                        0, ContainerHandle.DEFAULT_ASSIGN_ID,                         ContainerHandle.MODE_DEFAULT, tableProperties, 0);                if (cid1 < 0)                    throw T_Fail.testFailMsg("addContainer");                ContainerHandle c1 = t_util.t_openContainer(t, 0, cid1, true);                Page p1 = c1.getFirstPage();                if (p1.getPageNumber() != ContainerHandle.FIRST_PAGE_NUMBER)                    throw T_Fail.testFailMsg("expect first page to have FIRST_PAGE_NUMBER");                p1.unlatch();                if (c1.getNextPage(ContainerHandle.FIRST_PAGE_NUMBER) != null)                    throw T_Fail.testFailMsg("expect to have only 1 page allocated");                t_util.t_commit(t);                REPORT("AllocTest4 - create preallocated container " + cid1);                ////////////////////////////////////////////////////////                // next test special addpage interface                ////////////////////////////////////////////////////////                long cid2 = t_util.t_addContainer(t, 0, 1024, 0, 1, false);                t_util.t_commit(t);                ContainerHandle c2 = t_util.t_openContainer(t, 0, cid2, true);                // add page for bulk load                p1 = c2.addPage(ContainerHandle.ADD_PAGE_BULK);	                long pnum1 = p1.getPageNumber();                p1.unlatch();                // since the interface does not guarentee that anything special will                // actually happen, can't really test that. Just make sure that                // everything else works                Page p2 = c2.addPage();                long pnum2 = p2.getPageNumber();                p2.unlatch();                Page p3 = c2.addPage(ContainerHandle.ADD_PAGE_BULK);	                long pnum3 = p3.getPageNumber();                p3.unlatch();                Page p = c2.getFirstPage(); // this is the first page that came with the                                       // container when it was created                try                {                    long pnum0 = p.getPageNumber();                    p.unlatch();                    p = c2.getNextPage(pnum0);                    if (p.getPageNumber() != pnum1)                        throw T_Fail.testFailMsg("expected pagenum " + pnum1 + " got " + p.getPageNumber());                    p.unlatch();                    p = null;                    p = c2.getNextPage(pnum1);                    if (p.getPageNumber() != pnum2)                        throw T_Fail.testFailMsg("expected pagenum " + pnum2 + " got " + p.getPageNumber());                    p.unlatch();                    p = null;                    p = c2.getNextPage(pnum2);                    if (p.getPageNumber() != pnum3)                        throw T_Fail.testFailMsg("expected pagenum " + pnum3 + " got " + p.getPageNumber());                    p.unlatch();                    p = null;                    p = c2.getNextPage(pnum3);                    if (p != null)                        throw T_Fail.testFailMsg("expected null page after " + pnum3 +                                             " got " + p.getPageNumber());                    // make sure rollback is unaffected                    if (testRollback)                    {                        t_util.t_abort(t);                        c2 = t_util.t_openContainer(t, 0, cid2, true);                        p = t_util.t_getPage(c2, pnum0);                        t_util.t_checkEmptyPage(p);                        p.unlatch();                        p = null;                                        p = t_util.t_getPage(c2, pnum1);                        t_util.t_checkEmptyPage(p);                        p.unlatch();                        p = null;                        p = t_util.t_getPage(c2, pnum2);                        t_util.t_checkEmptyPage(p);                        p.unlatch();                        p = null;                        p = t_util.t_getPage(c2, pnum3);                        t_util.t_checkEmptyPage(p);                        p.unlatch();                        p = null;                        p = t_util.t_getLastPage(c2);                        if (p.getPageNumber() != pnum3)                            throw T_Fail.testFailMsg("expect last page to be " + pnum3                                                 + " got " + p.getPageNumber());                        p.unlatch();                        p = null;                    }                }                finally                {                    if (p != null)                        p.unlatch();                    p = null;                }                REPORT("AllocTest4 - special addPage interface " + cid2);                ////////////////////////////////////////////////////////                // next test preallocate interface                ////////////////////////////////////////////////////////			                long cid3 = t_util.t_addContainer(t, 0, 1024);                ContainerHandle c3 = t_util.t_openContainer(t, 0, cid3, true);                // now preallocate 10 pages                c3.preAllocate(10);                p1 = c3.getFirstPage();                if (p1.getPageNumber() != ContainerHandle.FIRST_PAGE_NUMBER)                    throw T_Fail.testFailMsg("expect first page to have FIRST_PAGE_NUMBER");                p1.unlatch();                if (c3.getNextPage(ContainerHandle.FIRST_PAGE_NUMBER) != null)                    throw T_Fail.testFailMsg("expect to have only 1 page allocated");                REPORT("AllocTest4 - preallocate interface " + cid3);                PASS("AllocTest4 ");            }            finally            {                SanityManager.DEBUG_CLEAR(AllocPage.TEST_MULTIPLE_ALLOC_PAGE);                t_util.t_commit(t);                t.close();            }        }	}	protected void AllocTest5() throws StandardException, T_Fail	{		// first create 10 1/2 filled pages with various degree of fillness		Transaction t = t_util.t_startTransaction();		try		{			long cid = t_util.t_addContainer(t, 0, 1024, 0, 90, false);			ContainerHandle c = t_util.t_openContainer(t, 0, cid, true);			Page p;			// the number of rows that is expected to fit into one page			// secret raw store calculation for 1 column rows			int numRows = (1024-60)/(95+8);			T_RawStoreRow rows[] = new T_RawStoreRow[numRows];			for (int j = 0; j < numRows; j++)				rows[j] = new T_RawStoreRow("row " + j);			for (int i = 0; i < numRows; i++)			{				p = t_util.t_addPage(c);				// validate allocation cache by getting the first page				t_util.t_getPage(c, 1).unlatch();				// insert different number of rows into these pages				for (int j = 0; j <= i; j++)				{					if (t_util.t_insert(p, rows[j]) == null)						throw T_Fail.testFailMsg("failed to insert " + (j+1) +												 " rows into page " + p);				}				p.unlatch();			}			// page 1 has 0 row			// page 2 has 1 row			// page 3 has 2 rows			// page 4 has 3 rows			// page 5 has 4 rows			// page 6 has 5 rows (filled)			// page 7 has 6 rows (filled)			// page 8 has 7 rows (filled)			// page 9 has 8 rows (filled)			// page 10 has 9 rows (filled)			// these pages should be accounted for correctly because each			// subsequent page has > 1/8 for all the records in the container			// now go thru and use up all the space			p =  c.getPageForInsert(0);			if (p != null)				throw T_Fail.testFailMsg("Expect last page to be full");			// now go thru and use up all the space - since we skipped page 1			// on the first loop, it won't know it is a 1/2 filled page.			for (int i = 2; i < 6; i++)			{				p = c.getPageForInsert(ContainerHandle.GET_PAGE_UNFILLED);				if (p == null)					throw T_Fail.testFailMsg("Expect next unfilled page to be " + i);				if (p.getPageNumber() != i)					throw T_Fail.testFailMsg("Expect next unfilled page to be "											 + i + ", it is " + p.getPageNumber());				t_util.t_insert(p, rows[i]);				p.unlatch();				// we should keep getting the same page back until it is full				while ((p = c.getPageForInsert(0)) != null)				{					if (p.getPageNumber() != i)						throw T_Fail.testFailMsg("Don't expect page number to change from " +												 i + " to " + p.getPageNumber());					t_util.t_insert(p, rows[i]);					p.unlatch();				}			}					p = c.getPageForInsert(ContainerHandle.GET_PAGE_UNFILLED);			if (p != null)				throw T_Fail.testFailMsg("don't expect any more pages to be found");		}		finally		{			t_util.t_commit(t);			t.close();		}		PASS("AllocTest5 ");	}	/*	 * MT tests on  the same container	 */	protected void AllocMTest1(long cid) throws StandardException, T_Fail 	{        if (SanityManager.DEBUG)        {            SanityManager.DEBUG_SET(AllocPage.TEST_MULTIPLE_ALLOC_PAGE);            // each thread will add N pages and remove N pages and still finds            // its own pages.  Do that serveral times.            int N = 20;            RecordHandle rh[] = new RecordHandle[N];            Transaction t = t_util.t_startTransaction();            try            {                T_RawStoreRow row = new T_RawStoreRow(REC_002);                ContainerHandle c;                Page p;                for (int iteration = 0; iteration < 5; iteration++)                {                    for (int i = 0; i < N; i++)                    {                        c = t_util.t_openContainer(t, 0, cid, true);                        p = t_util.t_addPage(c);                        rh[i] = t_util.t_insert(p, row);                        p.unlatch();                        t_util.t_commit(t);                    }                    for (int i = 0; i < N; i++)                    {                        c = t_util.t_openContainer(t, 0, cid, true);                        t_util.t_checkFetch(c, rh[i], REC_002);                        t.setSavePoint(SP1, null);                        p = t_util.t_getPage(c, rh[i].getPageNumber());                        t_util.t_removePage(c, p);                        if ((iteration%3) == 1)                        {                            t.rollbackToSavePoint(SP1, null);                        }                        // sometimes commit sometimes abort                        if (iteration % 2 == 0)                            t_util.t_abort(t);                        else                            t_util.t_commit(t);                    }                    // if I aborted, remove them now                    if ((iteration % 2) == 0 ||                        (iteration % 3) == 1)                    {                        for (int i = 0; i < N; i++)                        {                            c = t_util.t_openContainer(t, 0, cid, true);                            t_util.t_checkFetch(c, rh[i], REC_002);                            p = t_util.t_getPage(c, rh[i].getPageNumber());                            t_util.t_removePage(c, p);                            t_util.t_commit(t);                        }                    }                    // at any given time, there should be <= (N*numthread)+1 pages                    int max = (N*getNumThreads())+1;                    c = t_util.t_openContainer(t, 0, cid, false);                    long pnum = 0;                    int countPages = 0;                    for (p = c.getFirstPage();                         p != null;                         p = c.getNextPage(pnum))                    {                        countPages++;                        pnum = p.getPageNumber();                        p.unlatch();                        t_util.t_commit(t);	// release container lock                        c = t_util.t_openContainer(t, 0, cid, false);                    }                    t_util.t_commit(t);	// release container lock                    if (countPages > max)                        throw T_Fail.testFailMsg("some pages may not be reused, expect " +                                                 max + " got " + countPages);                    else                        REPORT("AllocMTest1 got " + countPages );                }                            }            finally            {                SanityManager.DEBUG_CLEAR(AllocPage.TEST_MULTIPLE_ALLOC_PAGE);                t_util.t_commit(t);                t.close();            }            PASS("AllocMTest1");        }        else        {			REPORT("AllocMTest1 cannot be run on an insane server");			return;        }	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -