joafip-svn Mailing List for java data object persistence in file (Page 12)
Brought to you by:
luc_peuvrier
You can subscribe to this list here.
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
(102) |
Nov
(52) |
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2012 |
Jan
(4) |
Feb
|
Mar
(14) |
Apr
(116) |
May
(100) |
Jun
(14) |
Jul
|
Aug
|
Sep
(30) |
Oct
|
Nov
(108) |
Dec
(2) |
|
From: <luc...@us...> - 2012-04-29 16:12:38
|
Revision: 3042
http://joafip.svn.sourceforge.net/joafip/?rev=3042&view=rev
Author: luc_peuvrier
Date: 2012-04-29 16:12:32 +0000 (Sun, 29 Apr 2012)
Log Message:
-----------
WIP btree plus: renamed because a heap file data manager dependent test
Modified Paths:
--------------
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/service/RecordServiceTests.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-29 16:07:14
|
Revision: 3041
http://joafip.svn.sourceforge.net/joafip/?rev=3041&view=rev
Author: luc_peuvrier
Date: 2012-04-29 16:07:07 +0000 (Sun, 29 Apr 2012)
Log Message:
-----------
WIP btree plus: renamed because a heap file data manager dependent test
Added Paths:
-----------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordStoreRestore.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
Copied: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordStoreRestore.java (from rev 3033, trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java)
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordStoreRestore.java (rev 0)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordStoreRestore.java 2012-04-29 16:07:07 UTC (rev 3041)
@@ -0,0 +1,360 @@
+/*
+ * Copyright 2007 Luc Peuvrier
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.heapfile.record.service;
+
+import java.io.File;
+
+import net.sf.joafip.AbstractCommonDeleteFileTestCase;
+import net.sf.joafip.DoNotTransform;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestConstant;
+import net.sf.joafip.TestException;
+import net.sf.joafip.heapfile.record.entity.HeapFreeNode;
+import net.sf.joafip.heapfile.record.entity.HeapHeader;
+import net.sf.joafip.heapfile.record.entity.HeapIdNode;
+import net.sf.joafip.heapfile.record.entity.HeapRecord;
+import net.sf.joafip.kvstore.entity.IFileStorable;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.record.service.IHeapRecordFactory;
+import net.sf.joafip.kvstore.service.FileForStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.redblacktree.service.RBTException;
+
+/**
+ * test {@link HeapRecord} store and restore
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+@DoNotTransform
+public class TestHeapRecordStoreRestore extends AbstractCommonDeleteFileTestCase
+ implements // NOPMD
+ IHeapElementManager {
+
+ private FileForStorable fileForStorable; // NOPMD
+
+ public TestHeapRecordStoreRestore() throws TestException {
+ super();
+ }
+
+ public TestHeapRecordStoreRestore(final String name) throws TestException {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {// NOPMD override test case
+ super.setUp();
+ final File file = new File(TestConstant.getWinRamDiskRuntimeDir()
+ + File.separator + "test.bin");
+ fileForStorable = new FileForStorable(file, 1, 0);
+ fileForStorable.open();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {// NOPMD override test case
+ try {
+ if (fileForStorable.isOpened()) {
+ fileForStorable.close();
+ }
+ } catch (Throwable throwable) {// NOPMD ignore all errors
+ }
+ fileForStorable = null;// NOPMD
+ super.tearDown();
+ }
+
+ public void testStoreRestore() throws Exception {// NOPMD
+ /*
+ * data record
+ */
+ HeapRecord heapRecord = new HeapRecord(
+ /**/this/*
+ * IHeapElementManager heapElementManager
+ */,
+ /**/0/* long positionInFile */,
+ /**/1L/* long previousRecordPositionInFile */,
+ /**/DataRecordIdentifier.ZERO/* long nodeIdentification */,
+ /**/false/* boolean freeRecord */,
+ /**/10/* int dataAssociatedSize */,
+ /**/100/* int areaSize */);
+ final HeapIdNode heapIdNode = (HeapIdNode) heapRecord.getIdNode();
+ heapIdNode.setLeftPositionInFile(2);
+ heapIdNode.setRightPositionInFile(3);
+ heapIdNode.setParentPositionInFile(4);
+ // byte[] data = heapRecord.getDataAssociated();
+ final byte[] data = new byte[10];
+ heapRecord.setDataAssociated(data);
+ System.arraycopy("0123456789".getBytes(), 0, data, 0, 10);
+ heapRecord.setValueIsChangedValueToSave();
+ heapRecord.writeToFile();
+ readAndCheck(heapRecord, data);
+
+ /*
+ * free record
+ */
+ heapRecord = new HeapRecord(
+ /**/this/*
+ * IHeapElementManager heapElementManager
+ */,
+ /**/0/* long positionInFile */,
+ /**/90L/* long previousRecordPositionInFile */,
+ /**/DataRecordIdentifier.ZERO/* long nodeIdentification */,
+ /**/true/* boolean freeRecord */,
+ /**/0/* int dataAssociatedSize */,
+ /**/100/* int areaSize */);
+
+ final HeapFreeNode heapFreeNode = (HeapFreeNode) heapRecord
+ .getFreeNode();
+ heapFreeNode.setLeftPositionInFile(91);
+ heapFreeNode.setRightPositionInFile(92);
+ heapFreeNode.setParentPositionInFile(93);
+ // to force write
+ heapRecord.setValueIsChangedValueToSave();
+ heapRecord.writeToFile();
+ readAndCheck(heapRecord, null);
+ }
+
+ /**
+ * @param heapRecordWrote
+ * @param expectedData
+ * @throws HeapException
+ * @throws RBTException
+ * @throws FileCorruptedException
+ */
+ private void readAndCheck(final HeapRecord heapRecordWrote,
+ final byte[] expectedData) throws HeapException, RBTException {
+ final HeapRecord heapRecordRead = new HeapRecord(
+ /**/this,/* IHeapElementManager heapElementManager */
+ /**/0/* long positionInFile */);
+ heapRecordRead.readFromFile();
+ assertHeapNodeEquals(heapRecordWrote, heapRecordRead, expectedData);
+ }
+
+ private void assertHeapNodeEquals(final HeapRecord heapRecordWrote,
+ final HeapRecord heapRecordRead, final byte[] expectedData)
+ throws HeapException, RBTException {
+
+ assertEquals("heap record file position error",
+ heapRecordWrote.getPositionInFile(),
+ heapRecordRead.getPositionInFile());
+ assertEquals("free record error", heapRecordWrote.isFreeRecord(),
+ heapRecordRead.isFreeRecord());
+ assertEquals("area size error", heapRecordWrote.getRecordSize(),
+ heapRecordRead.getRecordSize());
+ assertEquals("heap record previous file position error",
+ heapRecordWrote.getPreviousRecordPositionInFile(),
+ heapRecordRead.getPreviousRecordPositionInFile());
+
+ if (heapRecordWrote.isFreeRecord()) {
+
+ final HeapFreeNode heapFreeNode1 = (HeapFreeNode) heapRecordWrote
+ .getFreeNode();
+ final HeapFreeNode heapFreeNode2 = (HeapFreeNode) heapRecordRead
+ .getFreeNode();
+
+ assertEquals("free1 file pos error",
+ heapRecordWrote.getPositionInFile(),
+ heapFreeNode1.getPositionInFile());
+ assertEquals("free2 file pos error",
+ heapRecordRead.getPositionInFile(),
+ heapFreeNode2.getPositionInFile());
+ assertEquals("free parent file pos error",
+ heapFreeNode1.getParentPositionInFile(),
+ heapFreeNode1.getParentPositionInFile());
+ assertEquals("free right file pos error",
+ heapFreeNode1.getRightPositionInFile(),
+ heapFreeNode1.getRightPositionInFile());
+ assertEquals("free left file pos error",
+ heapFreeNode1.getLeftPositionInFile(),
+ heapFreeNode1.getLeftPositionInFile());
+
+ } else {
+ assertEquals("data size error",
+ heapRecordWrote.getDataAssociatedSize(),
+ heapRecordRead.getDataAssociatedSize());
+ assertEquals("node id error", heapRecordWrote.getNodeIdentifier(),
+ heapRecordRead.getNodeIdentifier());
+
+ final HeapIdNode heapIdNode1 = (HeapIdNode) heapRecordWrote
+ .getIdNode();
+ final HeapIdNode heapIdNode2 = (HeapIdNode) heapRecordRead
+ .getIdNode();
+
+ assertEquals("id1 file pos error",
+ heapRecordWrote.getPositionInFile(),
+ heapIdNode1.getPositionInFile());
+ assertEquals("id2 file pos error",
+ heapRecordRead.getPositionInFile(),
+ heapIdNode2.getPositionInFile());
+ assertEquals("id parent file pos error",
+ heapIdNode1.getParentPositionInFile(),
+ heapIdNode1.getParentPositionInFile());
+ assertEquals("id right file pos error",
+ heapIdNode1.getRightPositionInFile(),
+ heapIdNode1.getRightPositionInFile());
+ assertEquals("id left file pos error",
+ heapIdNode1.getLeftPositionInFile(),
+ heapIdNode1.getLeftPositionInFile());
+
+ final byte[] dataRead = heapRecordRead.getDataAssociated();
+ assertEquals("data length error", expectedData.length,
+ dataRead.length);
+ for (int index = 0; index < expectedData.length; index++) {
+ assertEquals("data error", expectedData[index], dataRead[index]);
+
+ }
+ }
+ }
+
+ /*
+ * mock for test, do nothing
+ */
+
+ @Override
+ public void appendHeapFileRecord(IFileStorable heapRecord) {// NOPMD do
+ // nothing
+ }
+
+ @Override
+ public void removeFiles() throws HeapException {
+ // do nothing
+ }
+
+ @Override
+ public void stopService() throws HeapException {// NOPMD do nothing
+ }
+
+ @Override
+ public void closeTransaction() throws HeapException {// NOPMD do nothing
+ }
+
+ @Override
+ public void closeTransactionDiscardChange() throws HeapException {// NOPMD
+ // do nothing
+ }
+
+ @Override
+ public void clear() throws HeapException {
+ // do nothing
+ }
+
+ @Override
+ public void delete(long positionInFile) {// NOPMD do nothing
+ }
+
+ @Override
+ public void setHeapHeader(final IFileStorable heapHeader)
+ throws HeapException {
+ // do nothing
+ }
+
+ @Override
+ public HeapHeader getHeapHeader() {
+ return null;
+ }
+
+ @Override
+ public long getFileSize() throws HeapException {
+ return 0;
+ }
+
+ @Override
+ public boolean isDataLost() {
+ return false;
+ }
+
+ @Override
+ public boolean isServiceStarted() {
+ return false;
+ }
+
+ @Override
+ public boolean isTransactionOpened() {
+ return false;
+ }
+
+ // @Override
+ // public HeapRecord newHeapFileRecord(final long positionInFile,
+ // final long previousRecordPositionInFile,
+ // final DataRecordIdentifier nodeIdentification,
+ // final boolean freeRecord, final Integer dataAssociatedSize,
+ // final int areaSize) throws HeapException {
+ // return null;
+ // }
+
+ @Override
+ public void startService() throws HeapException {// NOPMD do nothing
+ }
+
+ @Override
+ public void openTransaction() throws HeapException {// NOPMD do nothing
+ }
+
+ @Override
+ public IFileStorable readHeapFileDataRecord(final long positionInFile)
+ throws HeapException {
+ return null;
+ }
+
+ @Override
+ public boolean wasBadFileStableState() throws HeapException {
+ return false;
+ }
+
+ @Override
+ public FileForStorable getFileForStorable() {
+ return fileForStorable;
+ }
+
+ @Override
+ public boolean isCrashSafeMode() {
+ return false;
+ }
+
+ @Override
+ public int getNumberOfHeaprecordInMemory() {
+ throw new UnsupportedOperationException("not implemented");
+ }
+
+ @Override
+ public void setHeapRecordFactory(final IHeapRecordFactory heapRecordFactory) {
+ throw new UnsupportedOperationException("not implemented");
+ }
+
+ @Override
+ public IHeapRecordFactory getHeapRecordFactory() {
+ throw new UnsupportedOperationException("not implemented");
+ }
+
+ @Override
+ public void setDataRecordKeyManager(
+ final IDataRecordKeyManager dataRecordKeyComparator) {
+ throw new UnsupportedOperationException("not implemented");
+ }
+
+ @Override
+ public IDataRecordKeyManager getDataRecordKeyManager() {
+ throw new UnsupportedOperationException("not implemented");
+ }
+
+ @Override
+ public String backup(long identifier, int maxBackup) throws HeapException {
+ throw new UnsupportedOperationException("not implemented");
+ }
+}
Deleted: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-29 12:38:52 UTC (rev 3040)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-29 16:07:07 UTC (rev 3041)
@@ -1,360 +0,0 @@
-/*
- * Copyright 2007 Luc Peuvrier
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.joafip.heapfile.record.service;
-
-import java.io.File;
-
-import net.sf.joafip.AbstractCommonDeleteFileTestCase;
-import net.sf.joafip.DoNotTransform;
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.TestConstant;
-import net.sf.joafip.TestException;
-import net.sf.joafip.heapfile.record.entity.HeapFreeNode;
-import net.sf.joafip.heapfile.record.entity.HeapHeader;
-import net.sf.joafip.heapfile.record.entity.HeapIdNode;
-import net.sf.joafip.heapfile.record.entity.HeapRecord;
-import net.sf.joafip.kvstore.entity.IFileStorable;
-import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
-import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
-import net.sf.joafip.kvstore.record.service.IHeapElementManager;
-import net.sf.joafip.kvstore.record.service.IHeapRecordFactory;
-import net.sf.joafip.kvstore.service.FileForStorable;
-import net.sf.joafip.kvstore.service.HeapException;
-import net.sf.joafip.redblacktree.service.RBTException;
-
-/**
- * test {@link HeapRecord} store and restore
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-@DoNotTransform
-public class TestStoreRestore extends AbstractCommonDeleteFileTestCase
- implements // NOPMD
- IHeapElementManager {
-
- private FileForStorable fileForStorable; // NOPMD
-
- public TestStoreRestore() throws TestException {
- super();
- }
-
- public TestStoreRestore(final String name) throws TestException {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {// NOPMD override test case
- super.setUp();
- final File file = new File(TestConstant.getWinRamDiskRuntimeDir()
- + File.separator + "test.bin");
- fileForStorable = new FileForStorable(file, 1, 0);
- fileForStorable.open();
- }
-
- @Override
- protected void tearDown() throws Exception {// NOPMD override test case
- try {
- if (fileForStorable.isOpened()) {
- fileForStorable.close();
- }
- } catch (Throwable throwable) {// NOPMD ignore all errors
- }
- fileForStorable = null;// NOPMD
- super.tearDown();
- }
-
- public void testStoreRestore() throws Exception {// NOPMD
- /*
- * data record
- */
- HeapRecord heapRecord = new HeapRecord(
- /**/this/*
- * IHeapElementManager heapElementManager
- */,
- /**/0/* long positionInFile */,
- /**/1L/* long previousRecordPositionInFile */,
- /**/DataRecordIdentifier.ZERO/* long nodeIdentification */,
- /**/false/* boolean freeRecord */,
- /**/10/* int dataAssociatedSize */,
- /**/100/* int areaSize */);
- final HeapIdNode heapIdNode = (HeapIdNode) heapRecord.getIdNode();
- heapIdNode.setLeftPositionInFile(2);
- heapIdNode.setRightPositionInFile(3);
- heapIdNode.setParentPositionInFile(4);
- // byte[] data = heapRecord.getDataAssociated();
- final byte[] data = new byte[10];
- heapRecord.setDataAssociated(data);
- System.arraycopy("0123456789".getBytes(), 0, data, 0, 10);
- heapRecord.setValueIsChangedValueToSave();
- heapRecord.writeToFile();
- readAndCheck(heapRecord, data);
-
- /*
- * free record
- */
- heapRecord = new HeapRecord(
- /**/this/*
- * IHeapElementManager heapElementManager
- */,
- /**/0/* long positionInFile */,
- /**/90L/* long previousRecordPositionInFile */,
- /**/DataRecordIdentifier.ZERO/* long nodeIdentification */,
- /**/true/* boolean freeRecord */,
- /**/0/* int dataAssociatedSize */,
- /**/100/* int areaSize */);
-
- final HeapFreeNode heapFreeNode = (HeapFreeNode) heapRecord
- .getFreeNode();
- heapFreeNode.setLeftPositionInFile(91);
- heapFreeNode.setRightPositionInFile(92);
- heapFreeNode.setParentPositionInFile(93);
- // to force write
- heapRecord.setValueIsChangedValueToSave();
- heapRecord.writeToFile();
- readAndCheck(heapRecord, null);
- }
-
- /**
- * @param heapRecordWrote
- * @param expectedData
- * @throws HeapException
- * @throws RBTException
- * @throws FileCorruptedException
- */
- private void readAndCheck(final HeapRecord heapRecordWrote,
- final byte[] expectedData) throws HeapException, RBTException {
- final HeapRecord heapRecordRead = new HeapRecord(
- /**/this,/* IHeapElementManager heapElementManager */
- /**/0/* long positionInFile */);
- heapRecordRead.readFromFile();
- assertHeapNodeEquals(heapRecordWrote, heapRecordRead, expectedData);
- }
-
- private void assertHeapNodeEquals(final HeapRecord heapRecordWrote,
- final HeapRecord heapRecordRead, final byte[] expectedData)
- throws HeapException, RBTException {
-
- assertEquals("heap record file position error",
- heapRecordWrote.getPositionInFile(),
- heapRecordRead.getPositionInFile());
- assertEquals("free record error", heapRecordWrote.isFreeRecord(),
- heapRecordRead.isFreeRecord());
- assertEquals("area size error", heapRecordWrote.getRecordSize(),
- heapRecordRead.getRecordSize());
- assertEquals("heap record previous file position error",
- heapRecordWrote.getPreviousRecordPositionInFile(),
- heapRecordRead.getPreviousRecordPositionInFile());
-
- if (heapRecordWrote.isFreeRecord()) {
-
- final HeapFreeNode heapFreeNode1 = (HeapFreeNode) heapRecordWrote
- .getFreeNode();
- final HeapFreeNode heapFreeNode2 = (HeapFreeNode) heapRecordRead
- .getFreeNode();
-
- assertEquals("free1 file pos error",
- heapRecordWrote.getPositionInFile(),
- heapFreeNode1.getPositionInFile());
- assertEquals("free2 file pos error",
- heapRecordRead.getPositionInFile(),
- heapFreeNode2.getPositionInFile());
- assertEquals("free parent file pos error",
- heapFreeNode1.getParentPositionInFile(),
- heapFreeNode1.getParentPositionInFile());
- assertEquals("free right file pos error",
- heapFreeNode1.getRightPositionInFile(),
- heapFreeNode1.getRightPositionInFile());
- assertEquals("free left file pos error",
- heapFreeNode1.getLeftPositionInFile(),
- heapFreeNode1.getLeftPositionInFile());
-
- } else {
- assertEquals("data size error",
- heapRecordWrote.getDataAssociatedSize(),
- heapRecordRead.getDataAssociatedSize());
- assertEquals("node id error", heapRecordWrote.getNodeIdentifier(),
- heapRecordRead.getNodeIdentifier());
-
- final HeapIdNode heapIdNode1 = (HeapIdNode) heapRecordWrote
- .getIdNode();
- final HeapIdNode heapIdNode2 = (HeapIdNode) heapRecordRead
- .getIdNode();
-
- assertEquals("id1 file pos error",
- heapRecordWrote.getPositionInFile(),
- heapIdNode1.getPositionInFile());
- assertEquals("id2 file pos error",
- heapRecordRead.getPositionInFile(),
- heapIdNode2.getPositionInFile());
- assertEquals("id parent file pos error",
- heapIdNode1.getParentPositionInFile(),
- heapIdNode1.getParentPositionInFile());
- assertEquals("id right file pos error",
- heapIdNode1.getRightPositionInFile(),
- heapIdNode1.getRightPositionInFile());
- assertEquals("id left file pos error",
- heapIdNode1.getLeftPositionInFile(),
- heapIdNode1.getLeftPositionInFile());
-
- final byte[] dataRead = heapRecordRead.getDataAssociated();
- assertEquals("data length error", expectedData.length,
- dataRead.length);
- for (int index = 0; index < expectedData.length; index++) {
- assertEquals("data error", expectedData[index], dataRead[index]);
-
- }
- }
- }
-
- /*
- * mock for test, do nothing
- */
-
- @Override
- public void appendHeapFileRecord(IFileStorable heapRecord) {// NOPMD do
- // nothing
- }
-
- @Override
- public void removeFiles() throws HeapException {
- // do nothing
- }
-
- @Override
- public void stopService() throws HeapException {// NOPMD do nothing
- }
-
- @Override
- public void closeTransaction() throws HeapException {// NOPMD do nothing
- }
-
- @Override
- public void closeTransactionDiscardChange() throws HeapException {// NOPMD
- // do nothing
- }
-
- @Override
- public void clear() throws HeapException {
- // do nothing
- }
-
- @Override
- public void delete(long positionInFile) {// NOPMD do nothing
- }
-
- @Override
- public void setHeapHeader(final IFileStorable heapHeader)
- throws HeapException {
- // do nothing
- }
-
- @Override
- public HeapHeader getHeapHeader() {
- return null;
- }
-
- @Override
- public long getFileSize() throws HeapException {
- return 0;
- }
-
- @Override
- public boolean isDataLost() {
- return false;
- }
-
- @Override
- public boolean isServiceStarted() {
- return false;
- }
-
- @Override
- public boolean isTransactionOpened() {
- return false;
- }
-
- // @Override
- // public HeapRecord newHeapFileRecord(final long positionInFile,
- // final long previousRecordPositionInFile,
- // final DataRecordIdentifier nodeIdentification,
- // final boolean freeRecord, final Integer dataAssociatedSize,
- // final int areaSize) throws HeapException {
- // return null;
- // }
-
- @Override
- public void startService() throws HeapException {// NOPMD do nothing
- }
-
- @Override
- public void openTransaction() throws HeapException {// NOPMD do nothing
- }
-
- @Override
- public IFileStorable readHeapFileDataRecord(final long positionInFile)
- throws HeapException {
- return null;
- }
-
- @Override
- public boolean wasBadFileStableState() throws HeapException {
- return false;
- }
-
- @Override
- public FileForStorable getFileForStorable() {
- return fileForStorable;
- }
-
- @Override
- public boolean isCrashSafeMode() {
- return false;
- }
-
- @Override
- public int getNumberOfHeaprecordInMemory() {
- throw new UnsupportedOperationException("not implemented");
- }
-
- @Override
- public void setHeapRecordFactory(final IHeapRecordFactory heapRecordFactory) {
- throw new UnsupportedOperationException("not implemented");
- }
-
- @Override
- public IHeapRecordFactory getHeapRecordFactory() {
- throw new UnsupportedOperationException("not implemented");
- }
-
- @Override
- public void setDataRecordKeyManager(
- final IDataRecordKeyManager dataRecordKeyComparator) {
- throw new UnsupportedOperationException("not implemented");
- }
-
- @Override
- public IDataRecordKeyManager getDataRecordKeyManager() {
- throw new UnsupportedOperationException("not implemented");
- }
-
- @Override
- public String backup(long identifier, int maxBackup) throws HeapException {
- throw new UnsupportedOperationException("not implemented");
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-29 16:07:14
|
Revision: 3041
http://joafip.svn.sourceforge.net/joafip/?rev=3041&view=rev
Author: luc_peuvrier
Date: 2012-04-29 16:07:07 +0000 (Sun, 29 Apr 2012)
Log Message:
-----------
WIP btree plus: renamed because a heap file data manager dependent test
Added Paths:
-----------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordStoreRestore.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-29 12:38:58
|
Revision: 3040
http://joafip.svn.sourceforge.net/joafip/?rev=3040&view=rev
Author: luc_peuvrier
Date: 2012-04-29 12:38:52 +0000 (Sun, 29 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. non terminal page equilibrate, tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-29 12:38:58
|
Revision: 3040
http://joafip.svn.sourceforge.net/joafip/?rev=3040&view=rev
Author: luc_peuvrier
Date: 2012-04-29 12:38:52 +0000 (Sun, 29 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. non terminal page equilibrate, tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-29 04:53:50 UTC (rev 3039)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-29 12:38:52 UTC (rev 3040)
@@ -337,4 +337,106 @@
assert byteSize != 0 : "unknow current byte size";
return byteSize >= (PageConstant.PAGE_SIZE >> 1);
}
+
+ /**
+ * update {@link this#middleKey} if do not merge
+ *
+ * @param middleKey
+ * @param rightNonTerminalPage
+ * @return true if merge in this page, nonTerminalPage is to be destroyed
+ */
+ public boolean equilibrate(final DataRecordIdentifier middleKey,
+ final NonTerminalPage rightNonTerminalPage) {
+ assert byteSize != 0 : "unknow current byte size";
+ final int rightPageByteSize = rightNonTerminalPage.getByteSize();
+ final int middleKeySize = entrySize(middleKey);
+ final int rightPageNumberOfKeyEntries = rightNonTerminalPage.numberOfKeyEntries;
+ final int totalNumberOfEntries = numberOfKeyEntries
+ + rightPageNumberOfKeyEntries;
+ final boolean merged;
+ if (byteSize + middleKeySize + rightPageByteSize - HEAD_TAIL_SIZE <= PageConstant.PAGE_SIZE) {
+ // can merge
+ merged = true;
+ pagePositions = Arrays.copyOf(pagePositions,
+ totalNumberOfEntries + 1 + 1);
+ keys = Arrays.copyOf(keys, totalNumberOfEntries + 1);
+ System.arraycopy(rightNonTerminalPage.pagePositions, 0,
+ pagePositions, numberOfKeyEntries + 1,
+ rightPageNumberOfKeyEntries + 1);
+ keys[numberOfKeyEntries] = middleKey;
+ System.arraycopy(rightNonTerminalPage.keys, 0, keys,
+ numberOfKeyEntries + 1, rightPageNumberOfKeyEntries);
+ numberOfKeyEntries = totalNumberOfEntries + 1;
+ byteSize += middleKeySize + rightPageByteSize - HEAD_TAIL_SIZE;
+ // ASSERTX
+ assert byteSize == computeByteSize() : "byteSize=" + byteSize
+ + ", computed=" + computeByteSize();
+ } else {
+ merged = false;
+ final int newNumberOfEntries = totalNumberOfEntries / 2;
+ final int newRightPageNumberOfEntries = totalNumberOfEntries
+ - newNumberOfEntries;
+ if (newNumberOfEntries > numberOfKeyEntries) {
+ int length = newNumberOfEntries - numberOfKeyEntries;
+ pagePositions = Arrays.copyOf(pagePositions,
+ newNumberOfEntries + 1);
+ System.arraycopy(rightNonTerminalPage.pagePositions, 0,
+ pagePositions, numberOfKeyEntries + 1, length);
+ keys = Arrays.copyOf(keys, newNumberOfEntries);
+ keys[numberOfKeyEntries] = middleKey;
+ System.arraycopy(rightNonTerminalPage.keys, 0, keys,
+ numberOfKeyEntries + 1, length - 1);
+ this.middleKey = rightNonTerminalPage.keys[length - 1];
+ numberOfKeyEntries = newNumberOfEntries;
+ updateByteSize();
+ length = rightPageNumberOfKeyEntries
+ - newRightPageNumberOfEntries;
+ rightNonTerminalPage.pagePositions = Arrays.copyOfRange(
+ rightNonTerminalPage.pagePositions, length,
+ rightPageNumberOfKeyEntries + 1);
+ rightNonTerminalPage.keys = Arrays.copyOfRange(
+ rightNonTerminalPage.keys, length,
+ rightPageNumberOfKeyEntries);
+ rightNonTerminalPage.numberOfKeyEntries = newRightPageNumberOfEntries;
+ rightNonTerminalPage.updateByteSize();
+ } else if (newRightPageNumberOfEntries > rightPageNumberOfKeyEntries) {
+ final int length = newRightPageNumberOfEntries
+ - rightPageNumberOfKeyEntries;
+ long[] newPagePositions = Arrays.copyOf(pagePositions,
+ newNumberOfEntries + 1);
+ DataRecordIdentifier[] newKeys = Arrays.copyOf(keys,
+ newNumberOfEntries);
+ this.middleKey = keys[newNumberOfEntries];
+ long[] newRightPagePositions = new long[newRightPageNumberOfEntries + 1];
+ DataRecordIdentifier[] newRightKeys = new DataRecordIdentifier[newRightPageNumberOfEntries];
+ System.arraycopy(pagePositions, newNumberOfEntries + 1,
+ newRightPagePositions, 0, length);
+ System.arraycopy(keys, newNumberOfEntries + 1, newRightKeys, 0,
+ length - 1);
+ newRightKeys[length - 1] = middleKey;
+ System.arraycopy(rightNonTerminalPage.pagePositions, 0,
+ newRightPagePositions, length,
+ rightPageNumberOfKeyEntries + 1);
+ System.arraycopy(rightNonTerminalPage.keys, 0, newRightKeys,
+ length, rightPageNumberOfKeyEntries);
+ rightNonTerminalPage.numberOfKeyEntries = newRightPageNumberOfEntries;
+ rightNonTerminalPage.keys = newRightKeys;
+ rightNonTerminalPage.pagePositions = newRightPagePositions;
+ rightNonTerminalPage.updateByteSize();
+ numberOfKeyEntries = newNumberOfEntries;
+ keys = newKeys;
+ pagePositions = newPagePositions;
+ updateByteSize();
+ }
+ }
+ return merged;
+ }
+
+ public DataRecordIdentifier getLastKey() {
+ return keys[numberOfKeyEntries - 1];
+ }
+
+ public long getLastPagePosition() {
+ return pagePositions[numberOfKeyEntries];
+ }
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-29 04:53:50 UTC (rev 3039)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-29 12:38:52 UTC (rev 3040)
@@ -35,7 +35,6 @@
import net.sf.joafip.btreeplus.entity.IPageRecordable;
import net.sf.joafip.btreeplus.entity.LeafPage;
import net.sf.joafip.btreeplus.entity.NonTerminalPage;
-import net.sf.joafip.btreeplus.entity.PageConstant;
import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.HeapElementManagerFactory;
@@ -358,19 +357,96 @@
equilibrateFull(nonTerminalPage);
}
} else {
-
+ if (!nonTerminalPage.setKey(leafPageInParentIndex,
+ leafPage.getLastKey())) {
+ equilibrateFull(nonTerminalPage);
+ }
}
}
}
return deleted;
}
- private void equilibrate(final NonTerminalPage nonTerminalPage) {
- // FIXMELUC __________________to implement
- if (nonTerminalPage.wellFilled()) {
+ private void equilibrate(final NonTerminalPage nonTerminalPage)
+ throws HeapException {
+ if (!nonTerminalPage.wellFilled()) {
+ NonTerminalPage parentNonterminal = (NonTerminalPage) nonTerminalPage
+ .getParentPage();
+ if (parentNonterminal != null) {
+ int inParentIndex = nonTerminalPage.getInParentIndex();
+ if (inParentIndex != 0) {
+ final int leftPageInParentIndex = inParentIndex - 1;
+ final long leftPagePosition = nonTerminalPage
+ .getPagePointer(leftPageInParentIndex);
+ final NonTerminalPage leftPage = (NonTerminalPage) btreePlusElementMgr
+ .getPage(leftPagePosition, nonTerminalPage,
+ leftPageInParentIndex);
+ final DataRecordIdentifier middleKey = middleKey(leftPage);
+ if (leftPage.equilibrate(middleKey, nonTerminalPage)) {
+ // page merged in left page
+ btreePlusElementMgr.freePage(nonTerminalPage
+ .getPageRecord());
+ parentNonterminal.remove(inParentIndex);
+ if (parentNonterminal.setKey(leftPageInParentIndex,
+ leftPage.getAndClearMiddleKey())) {
+ equilibrate(parentNonterminal);
+ } else {
+ equilibrateFull(nonTerminalPage);
+ }
+ } else {
+ if (!nonTerminalPage.setKey(leftPageInParentIndex,
+ leftPage.getAndClearMiddleKey())) {
+ equilibrateFull(nonTerminalPage);
+ }
+ }
+ } else if (inParentIndex != nonTerminalPage
+ .getNumberOfKeyEntries() - 1) {
+ final int rightPageinParentIndex = inParentIndex + 1;
+ final long rightPagePosition = nonTerminalPage
+ .getPagePointer(rightPageinParentIndex);
+ final NonTerminalPage rightPage = (NonTerminalPage) btreePlusElementMgr
+ .getPage(rightPagePosition, nonTerminalPage,
+ rightPageinParentIndex);
+ final DataRecordIdentifier middleKey = middleKey(nonTerminalPage);
+ if (nonTerminalPage.equilibrate(middleKey, rightPage)) {
+ // right leaf page merged in leaf page
+ btreePlusElementMgr.freePage(rightPage.getPageRecord());
+ parentNonterminal.remove(rightPageinParentIndex);
+ if (parentNonterminal.setKey(inParentIndex,
+ nonTerminalPage.getAndClearMiddleKey())) {
+ equilibrate(parentNonterminal);
+ } else {
+ equilibrateFull(nonTerminalPage);
+ }
+ } else {
+ if (!nonTerminalPage.setKey(inParentIndex,
+ nonTerminalPage.getAndClearMiddleKey())) {
+ equilibrateFull(nonTerminalPage);
+ }
+ }
+ }
+ }
+ }
+ }
+ private DataRecordIdentifier middleKey(final NonTerminalPage nonTerminalPage)
+ throws HeapException {
+ final long position = nonTerminalPage.getLastPagePosition();
+ IPageRecordable pageRecordable = btreePlusElementMgr.getPage(position,
+ nonTerminalPage, nonTerminalPage.getNumberOfKeyEntries());
+ final DataRecordIdentifier result;
+ switch (pageRecordable.getRecordType()) {
+ case NON_TERMINAL_PAGE:
+ result = ((NonTerminalPage) pageRecordable).getLastKey();
+ break;
+ case LEAF_PAGE:
+ result = ((LeafPage) pageRecordable).getLastKey();
+ break;
+ default:
+ throw new HeapException(pageRecordable.getRecordType()
+ + " unexpected page type");
}
-
+ return result;
}
@Override
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java 2012-04-29 04:53:50 UTC (rev 3039)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java 2012-04-29 12:38:52 UTC (rev 3040)
@@ -422,6 +422,59 @@
/**/new long[] { 1000, 2000, 3000, 5000, 6000, 7000, 8000, 10000 });
}
+ public void testEquilibrateMerge() throws HeapException {
+ final NonTerminalPage leftPage = new NonTerminalPage(5);
+ final NonTerminalPage rightPage = new NonTerminalPage(5);
+ addToNonTerminalPage(leftPage,
+ /**/new int[] { 5, 7, 10, 15, 17 },
+ /**/new long[] { 2000, 4000, 1000, 3000, 5000, 6000 });
+ leftPage.updateByteSize();
+ addToNonTerminalPage(rightPage,
+ /**/new int[] { 50, 70, 100, 150, 170 },
+ /**/new long[] { 20000, 40000, 10000, 30000, 50000, 60000 });
+ rightPage.updateByteSize();
+ assertTrue("must merge",
+ leftPage.equilibrate(new DataRecordIdentifier(25), rightPage));
+ checkState(leftPage,
+ /**/new int[] { 5, 7, 10, 15, 17, 25, 50, 70, 100, 150, 170 },
+ /**/new long[] { 2000, 4000, 1000, 3000, 5000, 6000, 20000, 40000,
+ 10000, 30000, 50000, 60000 });
+ }
+
+ public void testEquilibrateRightToLeft() throws HeapException {
+ final NonTerminalPage leftPage = new NonTerminalPage(128 + 32);
+ final NonTerminalPage rightPage = new NonTerminalPage(128 + 64);
+ addToNonTerminalPage(leftPage, createKeys(1, 128 + 32),
+ createPointers(1, 128 + 32 + 1));
+ leftPage.updateByteSize();
+ addToNonTerminalPage(rightPage, createKeys(2 + 128 + 32, 128 + 64),
+ createPointers(1 + 128 + 32 + 1, 128 + 64 + 1));
+ rightPage.updateByteSize();
+ assertFalse("must not merge", leftPage.equilibrate(
+ new DataRecordIdentifier(128 + 32 + 1), rightPage));
+ checkState(leftPage, createKeys(1, 176), createPointers(1, 177));
+ assertEquals("bad middle key", 177,
+ leftPage.getAndClearMiddleKey().value);
+ checkState(rightPage, createKeys(178, 176), createPointers(178, 177));
+ }
+
+ public void testEquilibrateLeftToRight() throws HeapException {
+ final NonTerminalPage leftPage = new NonTerminalPage(128 + 64);
+ final NonTerminalPage rightPage = new NonTerminalPage(128 + 32);
+ addToNonTerminalPage(leftPage, createKeys(1, 128 + 64),
+ createPointers(1, 128 + 64 + 1));
+ leftPage.updateByteSize();
+ addToNonTerminalPage(rightPage, createKeys(2 + 128 + 64, 128 + 32),
+ createPointers(1 + 128 + 64 + 1, 128 + 32 + 1));
+ rightPage.updateByteSize();
+ assertFalse("must not merge", leftPage.equilibrate(
+ new DataRecordIdentifier(1 + 128 + 64), rightPage));
+ checkState(leftPage, createKeys(1, 176), createPointers(1, 177));
+ assertEquals("bad middle key", 177,
+ leftPage.getAndClearMiddleKey().value);
+ checkState(rightPage, createKeys(178, 176), createPointers(178, 177));
+ }
+
private void checkState(final NonTerminalPage nonTerminalPage,
final int[] keys, final long[] pointers) {
final int numberOfEntries = keys.length;
@@ -441,8 +494,38 @@
assertEquals("bad #" + numberOfEntries + " page pointer",
pointers[numberOfEntries],
nonTerminalPage.getPagePointer(numberOfEntries));
+ assertEquals("bad last key", keys[numberOfEntries - 1],
+ nonTerminalPage.getLastKey().value);
}
+ private void addToNonTerminalPage(final NonTerminalPage nonTerminalPage,
+ final int[] keys, final long[] pointers) throws HeapException {
+ int index;
+ for (index = 0; index < keys.length; index++) {
+ nonTerminalPage.setEntry(index, pointers[index],
+ new DataRecordIdentifier(keys[index]));
+ }
+ nonTerminalPage.setEntry(index, pointers[index], null);
+ }
+
+ private int[] createKeys(final int start, final int length) {
+ final int[] keys = new int[length];
+ int value = start;
+ for (int index = 0; index < length; index++) {
+ keys[index] = value++;
+ }
+ return keys;
+ }
+
+ private long[] createPointers(final long start, final int length) {
+ final long[] pointers = new long[length];
+ long value = start;
+ for (int index = 0; index < length; index++) {
+ pointers[index] = value++;
+ }
+ return pointers;
+ }
+
private MockLeafPage newMockLeafPage() throws HeapException {
final MockLeafPage mockLeafPage = new MockLeafPage();
mockLeafPage.setPageRecord(PAGE_RECORD);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-29 04:53:56
|
Revision: 3039
http://joafip.svn.sourceforge.net/joafip/?rev=3039&view=rev
Author: luc_peuvrier
Date: 2012-04-29 04:53:50 +0000 (Sun, 29 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. BtreePlusElementMgr added free page management, tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java 2012-04-29 04:09:15 UTC (rev 3038)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java 2012-04-29 04:53:50 UTC (rev 3039)
@@ -59,4 +59,6 @@
int getNumberOfPage();
+ long getPageNumber();
+
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java 2012-04-29 04:09:15 UTC (rev 3038)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java 2012-04-29 04:53:50 UTC (rev 3039)
@@ -40,6 +40,8 @@
private IPageRecordable pageRecordable;
+ private final long pageNumber;
+
/**
* creation for reading
*
@@ -49,11 +51,13 @@
public PageRecord(final IFileForStorable fileForStorable,
final long pageNumber) {
super(fileForStorable, pageNumber << PageConstant.PAGE_BITS);
+ this.pageNumber = pageNumber;
}
public PageRecord(final IFileForStorable fileForStorable,
final IPageRecordable pageRecordable, final long pageNumber) {
super(fileForStorable, pageNumber << PageConstant.PAGE_BITS);
+ this.pageNumber = pageNumber;
this.pageRecordable = pageRecordable;
this.recordType = pageRecordable.getRecordType();
}
@@ -62,6 +66,11 @@
return recordType;
}
+ @Override
+ public long getPageNumber() {
+ return pageNumber;
+ }
+
public IPageRecordable getPageRecordable() {
return pageRecordable;
}
@@ -210,6 +219,7 @@
assert pageRecordable.getByteSize() <= PageConstant.PAGE_SIZE;
final FreePage freePage = (FreePage) pageRecordable;
writeLong(freePage.getNextFreePage());
+ writeCrc32();
}
private void unmarshallFreePage() throws HeapException {
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-29 04:09:15 UTC (rev 3038)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-29 04:53:50 UTC (rev 3039)
@@ -26,6 +26,7 @@
import net.sf.joafip.Fortest;
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.btreeplus.entity.DataBlockPage;
+import net.sf.joafip.btreeplus.entity.FreePage;
import net.sf.joafip.btreeplus.entity.HeaderPage;
import net.sf.joafip.btreeplus.entity.IDataBlock;
import net.sf.joafip.btreeplus.entity.ILeafPage;
@@ -120,6 +121,7 @@
public IFileStorable createHeapRecord(
final IHeapElementManager heapElementManager,
final long positionInFile) throws HeapException {
+ // ASSERTX
assert (positionInFile & PageConstant.IN_PAGE_POSITION_MASK) == 0;
return new PageRecord(fileForStorable,
(int) (positionInFile >> PageConstant.PAGE_BITS));
@@ -152,17 +154,6 @@
return heapElementManager.backup(identifier, maxBackup);
}
- @Fortest
- public long getRecordPositionInfile(final DataRecordIdentifier identifier) {
- throw new UnsupportedOperationException("not implemented");
- }
-
- @Fortest
- public long getLastRecordPositionInFile() throws HeapException {
- return (header.getFileSizeAsNumberOfPage() - 1)
- * PageConstant.PAGE_SIZE;
- }
-
public long getNextFreeDataRecordIdentifier() {
return header.getNextFreeDataRecordIdentifier();
}
@@ -311,11 +302,27 @@
private void internalAppendPageRecordable(
final IPageRecordable pageRecordable) throws HeapException {
- long pageNumber = header.getFileSizeAsNumberOfPage();
+ long pageNumber = header.getPageNumberOfFirstFreePage();
+ boolean newPage;
+ if (pageNumber == -1) {
+ newPage = true;
+ pageNumber = header.getFileSizeAsNumberOfPage();
+ } else {
+ newPage = false;
+ final FreePage freePage = (FreePage) ((PageRecord) heapElementManager
+ .readHeapFileDataRecord(pageNumber << PageConstant.PAGE_BITS))
+ .getPageRecordable();
+ header.setPageNumberOfFirstFreePage(freePage.getNextFreePage());
+ }
final IPageRecord pageRecord = new PageRecord(fileForStorable,
pageRecordable, pageNumber);
- header.setFileSizeAsNumberOfPage(pageNumber
- + pageRecord.getNumberOfPage());
+ if (newPage) {
+ header.setFileSizeAsNumberOfPage(pageNumber
+ + pageRecord.getNumberOfPage());
+ } else {
+ // ASSERTX
+ assert pageRecord.getNumberOfPage() == 1;
+ }
pageRecordable.setPageRecord(pageRecord);
heapElementManager.appendHeapFileRecord(pageRecord);
}
@@ -325,8 +332,26 @@
|| pageRecordable instanceof NonTerminalPage;
}
- public void freePage(IPageRecord pageRecord) {
- // FIXMELUC _______________to implement
+ public void freePage(final IPageRecord pageRecord) throws HeapException {
+ final long freePageNumber = header.getPageNumberOfFirstFreePage();
+ FreePage freePage = new FreePage(freePageNumber);
+ final long newFreePageNumber = pageRecord.getPageNumber();
+ PageRecord pageRecord2 = new PageRecord(fileForStorable, freePage,
+ newFreePageNumber);
+ freePage.setPageRecord(pageRecord2);
+ freePage.setValueIsChangedValueToSave();
+ heapElementManager.appendHeapFileRecord(pageRecord2);
+ header.setPageNumberOfFirstFreePage(newFreePageNumber);
+ }
+ @Fortest
+ public long getRecordPositionInfile(final DataRecordIdentifier identifier) {
+ throw new UnsupportedOperationException("not implemented");
}
+
+ @Fortest
+ public long getLastRecordPositionInFile() throws HeapException {
+ return (header.getFileSizeAsNumberOfPage() - 1)
+ * PageConstant.PAGE_SIZE;
+ }
}
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java 2012-04-29 04:09:15 UTC (rev 3038)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java 2012-04-29 04:53:50 UTC (rev 3039)
@@ -40,6 +40,11 @@
}
@Override
+ public long getPageNumber() {
+ return 0;
+ }
+
+ @Override
public int getNumberOfPage() {
return 0;
}
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java 2012-04-29 04:09:15 UTC (rev 3038)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java 2012-04-29 04:53:50 UTC (rev 3039)
@@ -165,6 +165,44 @@
btreePlusElementMgr.closeTransactionDiscardChange();
}
+ public void testFreePage() throws HeapException {
+ btreePlusElementMgr.openTransaction();
+ assertEquals("must not has free page", -1, getHeapHeader()
+ .getPageNumberOfFirstFreePage());
+ IPageRecordable pageRecordable = new LeafPage();
+ btreePlusElementMgr.appendPageRecordable(pageRecordable);
+ pageRecordable.setValueIsChangedValueToSave();
+ pageRecordable = new LeafPage();
+ btreePlusElementMgr.appendPageRecordable(pageRecordable);
+ pageRecordable.setValueIsChangedValueToSave();
+ final long pageNumber = pageRecordable.getPageRecord().getPageNumber();
+ pageRecordable = new LeafPage();
+ btreePlusElementMgr.appendPageRecordable(pageRecordable);
+ pageRecordable.setValueIsChangedValueToSave();
+ btreePlusElementMgr.closeTransaction();
+
+ btreePlusElementMgr.openTransaction();
+ assertEquals("must not has free page", -1, getHeapHeader()
+ .getPageNumberOfFirstFreePage());
+ final IPageRecord pageRecord = btreePlusElementMgr
+ .getPage(pageNumber << PageConstant.PAGE_BITS,
+ null/* parentPage */, -1/* index */).getPageRecord();
+ btreePlusElementMgr.freePage(pageRecord);
+ btreePlusElementMgr.closeTransaction();
+
+ btreePlusElementMgr.openTransaction();
+ assertEquals("must has free page", pageNumber, getHeapHeader()
+ .getPageNumberOfFirstFreePage());
+ pageRecordable = new LeafPage();
+ btreePlusElementMgr.appendPageRecordable(pageRecordable);
+ pageRecordable.setValueIsChangedValueToSave();
+ final long pageNumber2 = pageRecordable.getPageRecord().getPageNumber();
+ assertEquals("must reuse", pageNumber, pageNumber2);
+ assertEquals("must not has free page", -1, getHeapHeader()
+ .getPageNumberOfFirstFreePage());
+ btreePlusElementMgr.closeTransaction();
+ }
+
public void testDataBlock() throws HeapException {
TestDataBlockContext[] contextByBits = new TestDataBlockContext[PageConstant.NUMBER_OF_BLOCK_TYPE];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-29 04:53:56
|
Revision: 3039
http://joafip.svn.sourceforge.net/joafip/?rev=3039&view=rev
Author: luc_peuvrier
Date: 2012-04-29 04:53:50 +0000 (Sun, 29 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. BtreePlusElementMgr added free page management, tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-29 04:09:22
|
Revision: 3038
http://joafip.svn.sourceforge.net/joafip/?rev=3038&view=rev
Author: luc_peuvrier
Date: 2012-04-29 04:09:15 +0000 (Sun, 29 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. leaf page equilibrate and non terminal page remove added, tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java 2012-04-28 22:10:12 UTC (rev 3037)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java 2012-04-29 04:09:15 UTC (rev 3038)
@@ -52,6 +52,10 @@
private long position = -1;
+ private LeafPage parentLeafPage;
+
+ private int indexInLeafPage;
+
public DataBlock(final DataBlockPage dataBlockPage,
final int indexInDataBlockPage, final byte bits, final int minSize,
final int maxSize) {
@@ -148,4 +152,21 @@
}
return position;
}
+
+ @Override
+ public void setParent(final LeafPage parentLeafPage,
+ final int indexInLeafPage) {
+ this.parentLeafPage = parentLeafPage;
+ this.indexInLeafPage = indexInLeafPage;
+ }
+
+ @Override
+ public LeafPage getParentLeafPage() {
+ return parentLeafPage;
+ }
+
+ @Override
+ public int getIndexInLeafPage() {
+ return indexInLeafPage;
+ }
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java 2012-04-28 22:10:12 UTC (rev 3037)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java 2012-04-29 04:09:15 UTC (rev 3038)
@@ -38,6 +38,8 @@
/**/1/* byte size for record type */+
/**/1/* byte size for bits */;
+ public static final int HEAD_TAIL_SIZE = HEAD_SIZE + 4/* crc32 */;
+
private byte bits;
private final int numberOfPage;
@@ -62,17 +64,17 @@
super();
this.bits = bits;
dataBlockDataSize = 1 << bits;
- if (dataBlockDataSize > PageConstant.PAGE_SIZE - HEAD_SIZE - 4/* crc32 */) {
+ if (dataBlockDataSize > PageConstant.PAGE_SIZE - HEAD_TAIL_SIZE) {
// one data block on one or more pages
numberOfBlock = 1;
- final int totalSize = HEAD_SIZE + dataBlockDataSize + 4/* crc32 */;
+ final int totalSize = HEAD_TAIL_SIZE + dataBlockDataSize;
final int n = totalSize >> PageConstant.PAGE_BITS;
if ((totalSize & PageConstant.IN_PAGE_POSITION_MASK) == 0) {
numberOfPage = n;
} else {
numberOfPage = n + 1;
}
- // FIXMELUC ____________waste space, see below
+ // FIXMELUC ________waste space, see below
// dataBlockDataSize=(numberOfPage<<PageConstant.PAGE_BITS)-
// HEAD_SIZE - 4/* crc32 */
} else {
@@ -80,7 +82,7 @@
numberOfPage = 1;
// numberOfBlock = ((int)PageConstant.PAGE_SIZE - FIX_VALUE_SIZE)
// / dataBlockDataSize;
- numberOfBlock = ((int) PageConstant.PAGE_SIZE - HEAD_SIZE - 4/* crc32 */) >> bits;
+ numberOfBlock = ((int) PageConstant.PAGE_SIZE - HEAD_TAIL_SIZE) >> bits;
}
final int minSize = bits == PageConstant.MIN_DATA_BLOCK_BITS ? 0
: ((1 << (bits - 1)) + 1);
@@ -114,7 +116,7 @@
@Override
public int getByteSize() {
return numberOfPage * (int) PageConstant.PAGE_SIZE;
- // FIXMELUC _____________use <<
+ // FIXMELUC ________use <<
// return numberOfPage <<PageConstant.PAGE_BITS
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java 2012-04-28 22:10:12 UTC (rev 3037)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java 2012-04-29 04:09:15 UTC (rev 3038)
@@ -65,4 +65,9 @@
int getIndexInDataBlockPage();
+ void setParent(LeafPage parentLeafPage, int indexInLeafPage);
+
+ LeafPage getParentLeafPage();
+
+ int getIndexInLeafPage();
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java 2012-04-28 22:10:12 UTC (rev 3037)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java 2012-04-29 04:09:15 UTC (rev 3038)
@@ -37,6 +37,11 @@
@NotStorableClass
public class LeafPage extends AbstractElement implements ILeafPage {
+ public static int HEAD_TAIL_SIZE = 1/* byte size for record type */+
+ /**/4/* int size for number of entries */+
+ /**/4/* int size for crc32 */+
+ /**/8/* for next */;
+
private long[] dataBlockPosition;
private DataRecordIdentifier[] keys;
@@ -51,6 +56,8 @@
private int inParentIndex;
+ private int index;
+
public LeafPage() {
this(0);
updateByteSize();
@@ -144,11 +151,8 @@
}
private int computeByteSize() {
- int xbyteSize = 1/* byte size for record type */+
- /**/4/* int size for number of entries */+
- /**/4/* int size for crc32 */+
- /**/8/* for next */;
- // FIXMELUC ______speedup if long value key
+ int xbyteSize = HEAD_TAIL_SIZE;
+ // FIXMELUC ________speedup if long value key
for (int index = 0; index < numberOfKeyEntries; index++) {
xbyteSize += entrySize(keys[index]);
}
@@ -163,9 +167,9 @@
*/
public long getDataBlockPosition(
final DataRecordIdentifier dataRecordIdentifier) {
- // FIXMELUC _______dichotomic search
+ // FIXMELUC _________dichotomic search
long position = -1;
- for (int index = 0; position == -1L && index < numberOfKeyEntries; index++) {
+ for (index = 0; position == -1L && index < numberOfKeyEntries; index++) {
if (keys[index].compareTo(dataRecordIdentifier) == 0) {
position = dataBlockPosition[index];
}
@@ -173,6 +177,10 @@
return position;
}
+ public int getIndex() {
+ return index;
+ }
+
public void setDataBlock(final int index, final IDataBlock dataBlock)
throws HeapException {
dataBlockPosition[index] = dataBlock.getPositionInFile();
@@ -262,6 +270,40 @@
return newLeafPage;
}
+ public void remove(final int index) throws HeapException {
+ DataRecordIdentifier dataRecordIdentifier = keys[index];
+ final int entrySize = entrySize(dataRecordIdentifier);
+ // ASSERTX
+ assert byteSize != 0 : "unknow current byte size";
+ final int afterLength = numberOfKeyEntries - (index + 1);
+ numberOfKeyEntries--;
+ final long[] newDataBlockPosition = new long[numberOfKeyEntries];
+ final DataRecordIdentifier[] newKeys = new DataRecordIdentifier[numberOfKeyEntries];
+ if (index != 0) {
+ System.arraycopy(dataBlockPosition, 0, newDataBlockPosition, 0,
+ index);
+ System.arraycopy(keys, 0, newKeys, 0, index);
+ }
+ if (afterLength != 0) {
+ System.arraycopy(dataBlockPosition, index + 1,
+ newDataBlockPosition, index, afterLength);
+ System.arraycopy(keys, index + 1, newKeys, index, afterLength);
+ }
+ keys = newKeys;
+ dataBlockPosition = newDataBlockPosition;
+ byteSize -= entrySize;
+ // ASSERTX
+ assert byteSize == computeByteSize() : byteSize + " for "
+ + computeByteSize() + " computed";
+ setValueIsChangedValueToSave();
+ }
+
+ public boolean wellFilled() {
+ // ASSERTX
+ assert byteSize != 0 : "unknow current byte size";
+ return byteSize >= (PageConstant.PAGE_SIZE >> 1);
+ }
+
private int computeInsertBeforeIndex(
final DataRecordIdentifier dataRecordIdentifier) {
int index;
@@ -274,4 +316,83 @@
public DataRecordIdentifier getLastKey() {
return keys[numberOfKeyEntries - 1];
}
+
+ /**
+ *
+ * @param leafPage
+ * @return true if merge in this page, leafPage is to be destroyed
+ */
+ public boolean equilibrate(final LeafPage leafPage) {
+ // ASSERTX
+ assert byteSize != 0 : "unknow current byte size";
+ final int leafPageByteSize = leafPage.getByteSize();
+ final int leafPageNumberOfKeyEntries = leafPage.numberOfKeyEntries;
+ final int totalNumberOfEntries = numberOfKeyEntries
+ + leafPageNumberOfKeyEntries;
+ final boolean merged;
+ if (byteSize + leafPageByteSize - HEAD_TAIL_SIZE <= PageConstant.PAGE_SIZE) {
+ merged = true;
+ dataBlockPosition = Arrays.copyOf(dataBlockPosition,
+ totalNumberOfEntries);
+ keys = Arrays.copyOf(keys, totalNumberOfEntries);
+ System.arraycopy(leafPage.dataBlockPosition, 0, dataBlockPosition,
+ numberOfKeyEntries, leafPageNumberOfKeyEntries);
+ System.arraycopy(leafPage.keys, 0, keys, numberOfKeyEntries,
+ leafPageNumberOfKeyEntries);
+ numberOfKeyEntries = totalNumberOfEntries;
+ // can merge
+ byteSize += leafPageByteSize - HEAD_TAIL_SIZE;
+ // ASSERTX
+ assert byteSize == computeByteSize() : byteSize + " for "
+ + computeByteSize() + " computed";
+ } else {
+ merged = false;
+ final int newNumberOfEntries = totalNumberOfEntries / 2;
+ final int newLeafPageNumberOfEntries = totalNumberOfEntries
+ - newNumberOfEntries;
+ if (newNumberOfEntries > numberOfKeyEntries) {
+ dataBlockPosition = Arrays.copyOf(dataBlockPosition,
+ newNumberOfEntries);
+ keys = Arrays.copyOf(keys, newNumberOfEntries);
+ final int length = newNumberOfEntries - numberOfKeyEntries;
+ System.arraycopy(leafPage.dataBlockPosition, 0,
+ dataBlockPosition, numberOfKeyEntries, length);
+ System.arraycopy(leafPage.keys, 0, keys, numberOfKeyEntries,
+ length);
+ leafPage.dataBlockPosition = Arrays.copyOfRange(
+ leafPage.dataBlockPosition, length,
+ leafPageNumberOfKeyEntries);
+ leafPage.keys = Arrays.copyOfRange(leafPage.keys, length,
+ leafPageNumberOfKeyEntries);
+ numberOfKeyEntries = newNumberOfEntries;
+ leafPage.numberOfKeyEntries = newLeafPageNumberOfEntries;
+ updateByteSize();
+ leafPage.updateByteSize();
+ } else if (newLeafPageNumberOfEntries > leafPageNumberOfKeyEntries) {
+ long[] newLeafPageDataBlockPosition = new long[newLeafPageNumberOfEntries];
+ DataRecordIdentifier[] newLeafPageKeys = new DataRecordIdentifier[newLeafPageNumberOfEntries];
+ final int length = newLeafPageNumberOfEntries
+ - leafPageNumberOfKeyEntries;
+ System.arraycopy(dataBlockPosition, newNumberOfEntries,
+ newLeafPageDataBlockPosition, 0, length);
+ System.arraycopy(keys, newNumberOfEntries, newLeafPageKeys, 0,
+ length);
+ System.arraycopy(leafPage.dataBlockPosition, 0,
+ newLeafPageDataBlockPosition, length,
+ leafPageNumberOfKeyEntries);
+ System.arraycopy(leafPage.keys, 0, newLeafPageKeys, length,
+ leafPageNumberOfKeyEntries);
+ dataBlockPosition = Arrays.copyOf(dataBlockPosition,
+ newNumberOfEntries);
+ keys = Arrays.copyOf(keys, newNumberOfEntries);
+ leafPage.dataBlockPosition = newLeafPageDataBlockPosition;
+ leafPage.keys = newLeafPageKeys;
+ numberOfKeyEntries = newNumberOfEntries;
+ leafPage.numberOfKeyEntries = newLeafPageNumberOfEntries;
+ updateByteSize();
+ leafPage.updateByteSize();
+ }// else no changes
+ }
+ return merged;
+ }
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-28 22:10:12 UTC (rev 3037)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-29 04:09:15 UTC (rev 3038)
@@ -38,6 +38,11 @@
public class NonTerminalPage extends AbstractElement implements
INonTerminalPage {
+ public static int HEAD_TAIL_SIZE = 1/* byte size for record type */+
+ /**/4/* int size for number of entries */+
+ /**/4/* int size for crc32 */+
+ /**/8/* last pointer long size */;
+
private long[] pagePositions;
private DataRecordIdentifier[] keys;
@@ -112,6 +117,25 @@
setValueIsChangedValueToSave();
}
+ /**
+ * change key
+ *
+ * @param index
+ * @param key
+ * @return true if not need to split (not too big)
+ * @throws HeapException
+ */
+ public boolean setKey(final int index, final DataRecordIdentifier key)
+ throws HeapException {
+ DataRecordIdentifier oldKey = keys[index];
+ keys[index] = key;
+ byteSize = byteSize - entrySize(oldKey) + entrySize(key);
+ // ASSERTX
+ assert byteSize == computeByteSize();
+ setValueIsChangedValueToSave();
+ return byteSize < PageConstant.PAGE_SIZE;
+ }
+
@Override
public int getByteSize() {
// ASSERTX
@@ -125,11 +149,8 @@
}
private int computeByteSize() {
- int xbyteSize = 1/* byte size for record type */+
- /**/4/* int size for number of entries */+
- /**/4/* int size for crc32 */+
- /**/8/* last pointer long size */;
- // FIXMELUC ______speedup if long value key
+ int xbyteSize = HEAD_TAIL_SIZE;
+ // FIXMELUC ________speedup if long value key
for (int index = 0; index < numberOfKeyEntries; index++) {
xbyteSize += entrySize(keys[index]);
}
@@ -157,7 +178,7 @@
* @return sub page index for data record identifier
*/
public int getIndex(final DataRecordIdentifier dataRecordIdentifier) {
- // FIXMELUC _______dichotomic search
+ // FIXMELUC _________dichotomic search
int index;
for (index = 0; index < numberOfKeyEntries; index++) {
if (keys[index].compareTo(dataRecordIdentifier) >= 0) {
@@ -283,4 +304,37 @@
middleKey = null;
return result;
}
+
+ public void remove(int leafPageInParentIndex) {
+ final DataRecordIdentifier key = keys[leafPageInParentIndex];
+ numberOfKeyEntries--;
+ DataRecordIdentifier[] newKeys = new DataRecordIdentifier[numberOfKeyEntries];
+ long[] newPagePositions = new long[numberOfKeyEntries + 1];
+ if (leafPageInParentIndex != 0) {
+ System.arraycopy(keys, 0, newKeys, 0, leafPageInParentIndex);
+ System.arraycopy(pagePositions, 0, newPagePositions, 0,
+ leafPageInParentIndex);
+ }
+ final int length = numberOfKeyEntries - leafPageInParentIndex;
+ if (length != 0) {
+ System.arraycopy(keys, leafPageInParentIndex + 1, newKeys,
+ leafPageInParentIndex, length);
+ }
+ System.arraycopy(pagePositions, leafPageInParentIndex + 1,
+ newPagePositions, leafPageInParentIndex, length + 1);
+ keys = newKeys;
+ pagePositions = newPagePositions;
+ // ASSERTX
+ assert byteSize != 0 : "unknow current byte size";
+ byteSize -= entrySize(key);
+ // ASSERTX
+ assert byteSize == computeByteSize() : "byteSize=" + byteSize
+ + ", computed=" + computeByteSize();
+ }
+
+ public boolean wellFilled() {
+ // ASSERTX
+ assert byteSize != 0 : "unknow current byte size";
+ return byteSize >= (PageConstant.PAGE_SIZE >> 1);
+ }
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-28 22:10:12 UTC (rev 3037)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-29 04:09:15 UTC (rev 3038)
@@ -35,6 +35,7 @@
import net.sf.joafip.btreeplus.entity.IPageRecordable;
import net.sf.joafip.btreeplus.entity.LeafPage;
import net.sf.joafip.btreeplus.entity.NonTerminalPage;
+import net.sf.joafip.btreeplus.entity.PageConstant;
import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.HeapElementManagerFactory;
@@ -198,39 +199,6 @@
return dataBlockPosition != -1L;
}
- private long dataBlockPosition(final IPageRecordable root,
- final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- final long dataBlockPosition;
- final LeafPage leafPage = leafPage(root, dataRecordIdentifier);
- if (leafPage == null) {
- dataBlockPosition = -1L;
- } else {
- dataBlockPosition = leafPage
- .getDataBlockPosition(dataRecordIdentifier);
- }
- return dataBlockPosition;
- }
-
- private LeafPage leafPage(final IPageRecordable root,
- final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- IPageRecordable page;
- if (root == null) {
- page = null;
- } else {
- page = root;
- while (!EnumRecordType.LEAF_PAGE.equals(page)) {
- final NonTerminalPage nonTerminalPage = (NonTerminalPage) page;
- final int index = nonTerminalPage
- .getIndex(dataRecordIdentifier);
- final long pagePosition = nonTerminalPage.getPagePointer(index);
- page = btreePlusElementMgr.getPage(pagePosition, page, index);
- }
- }
- return (LeafPage) page;
- }
-
@Override
protected boolean writeDataRecordImpl(
final DataRecordIdentifier dataRecordIdentifier, final byte[] data)
@@ -246,6 +214,7 @@
btreePlusElementMgr
.newRootLeafPage(dataRecordIdentifier, dataBlock);
} else {
+ // existing data
long dataBlockPosition = leafPage
.getDataBlockPosition(dataRecordIdentifier);
if (dataBlockPosition == -1) {
@@ -254,6 +223,7 @@
final IDataBlock dataBlock = btreePlusElementMgr
.createDataBlock(data);
if (!leafPage.add(dataRecordIdentifier, dataBlock)) {
+ // FIXMELUC ________rotation, dispatch on sibling
LeafPage newLeafPage = leafPage.split(dataRecordIdentifier,
dataBlock);
btreePlusElementMgr.appendPageRecordable(newLeafPage);
@@ -267,31 +237,7 @@
newLeafPage);
} else {
if (!nonTerminalPage.add(leafPage, newLeafPage)) {
- INonTerminalPage newNonTerminalPage = nonTerminalPage
- .split();
- do {
- btreePlusElementMgr
- .appendPageRecordable(newNonTerminalPage);
- newNonTerminalPage
- .setValueIsChangedValueToSave();
- DataRecordIdentifier middleKey = nonTerminalPage
- .getAndClearMiddleKey();
- NonTerminalPage parent = (NonTerminalPage) nonTerminalPage
- .getParentPage();
- if (parent == null) {
- btreePlusElementMgr.newRootNonTerminalPage(
- nonTerminalPage, middleKey,
- newNonTerminalPage);
- } else {
- if (parent.add(nonTerminalPage, middleKey,
- newNonTerminalPage)) {
- newNonTerminalPage = null;
- } else {
- newNonTerminalPage = nonTerminalPage
- .split();
- }
- }
- } while (newNonTerminalPage != null);
+ equilibrateFull(nonTerminalPage);
}
}
}
@@ -315,14 +261,118 @@
return created;
}
+ /**
+ *
+ * @param nonTerminalPage
+ * a too big page
+ * @throws HeapException
+ */
+ private void equilibrateFull(NonTerminalPage nonTerminalPage)
+ throws HeapException {
+ // FIXMELUC ________rotation, dispatch on sibling
+ INonTerminalPage newNonTerminalPage = nonTerminalPage.split();
+ do {
+ btreePlusElementMgr.appendPageRecordable(newNonTerminalPage);
+ newNonTerminalPage.setValueIsChangedValueToSave();
+ DataRecordIdentifier middleKey = nonTerminalPage
+ .getAndClearMiddleKey();
+ NonTerminalPage parent = (NonTerminalPage) nonTerminalPage
+ .getParentPage();
+ if (parent == null) {
+ btreePlusElementMgr.newRootNonTerminalPage(nonTerminalPage,
+ middleKey, newNonTerminalPage);
+ } else {
+ if (parent.add(nonTerminalPage, middleKey, newNonTerminalPage)) {
+ newNonTerminalPage = null;
+ } else {
+ newNonTerminalPage = nonTerminalPage.split();
+ }
+ }
+ } while (newNonTerminalPage != null);
+ }
+
@Override
protected boolean deleteDataRecordImpl(
final DataRecordIdentifier dataRecordIdentifier)
throws HeapException {
- // FIXMELUC ________to implement
- throw new HeapException("not implemented");
+ final boolean deleted;
+ final IDataBlock dataBlock = dataBlock(dataRecordIdentifier);
+ if (dataBlock == null) {
+ deleted = false;
+ } else {
+ deleted = true;
+ LeafPage leafPage = dataBlock.getParentLeafPage();
+ int indexInLeafPage = dataBlock.getIndexInLeafPage();
+ btreePlusElementMgr.remove(dataBlock);
+ leafPage.remove(indexInLeafPage);
+ final NonTerminalPage nonTerminalPage = (NonTerminalPage) leafPage
+ .getParentPage();
+ final int leafPageInParentIndex = leafPage.getInParentIndex();
+ if (leafPage.wellFilled()) {
+ if (leafPageInParentIndex != nonTerminalPage
+ .getNumberOfKeyEntries()) {
+ if (!nonTerminalPage.setKey(leafPageInParentIndex,
+ leafPage.getLastKey())) {
+ equilibrateFull(nonTerminalPage);
+ }
+ }
+ } else if (leafPageInParentIndex != 0) {
+ final int leftLeafPageInParentIndex = leafPageInParentIndex - 1;
+ final long leftLeafPagePosition = nonTerminalPage
+ .getPagePointer(leftLeafPageInParentIndex);
+ final LeafPage leftLeafPage = (LeafPage) btreePlusElementMgr
+ .getPage(leftLeafPagePosition, nonTerminalPage,
+ leftLeafPageInParentIndex);
+ if (leftLeafPage.equilibrate(leafPage)) {
+ // leaf page merged in left leaf page
+ btreePlusElementMgr.freePage(leafPage.getPageRecord());
+ nonTerminalPage.remove(leafPageInParentIndex);
+ if (nonTerminalPage.setKey(leftLeafPageInParentIndex,
+ leftLeafPage.getLastKey())) {
+ equilibrate(nonTerminalPage);
+ } else {
+ equilibrateFull(nonTerminalPage);
+ }
+ } else {
+ if (!nonTerminalPage.setKey(leftLeafPageInParentIndex,
+ leftLeafPage.getLastKey())) {
+ equilibrateFull(nonTerminalPage);
+ }
+ }
+ } else if (leafPageInParentIndex != nonTerminalPage
+ .getNumberOfKeyEntries() - 1) {
+ final int rightLeafPageinParentIndex = leafPageInParentIndex + 1;
+ final long rightLeafPagePosition = nonTerminalPage
+ .getPagePointer(rightLeafPageinParentIndex);
+ final LeafPage rightLeafPage = (LeafPage) btreePlusElementMgr
+ .getPage(rightLeafPagePosition, nonTerminalPage,
+ rightLeafPageinParentIndex);
+ if (leafPage.equilibrate(rightLeafPage)) {
+ // right leaf page merged in leaf page
+ btreePlusElementMgr.freePage(rightLeafPage.getPageRecord());
+ nonTerminalPage.remove(rightLeafPageinParentIndex);
+ if (nonTerminalPage.setKey(leafPageInParentIndex,
+ leafPage.getLastKey())) {
+ equilibrate(nonTerminalPage);
+ } else {
+ equilibrateFull(nonTerminalPage);
+ }
+ } else {
+
+ }
+ }
+ }
+ return deleted;
}
+ private void equilibrate(final NonTerminalPage nonTerminalPage) {
+ // FIXMELUC __________________to implement
+ if (nonTerminalPage.wellFilled()) {
+
+ }
+
+ }
+
@Override
protected DataRecordIdentifier removeFirstDataRecordImpl()
throws HeapException {
@@ -342,20 +392,62 @@
throw new HeapException("not implemented");
}
- @Override
- protected Set<DataRecordIdentifier> getDataRecordIdentifierSetImpl()
+ private long dataBlockPosition(final IPageRecordable root,
+ final DataRecordIdentifier dataRecordIdentifier)
throws HeapException {
- // FIXMELUC ________to implement
- throw new HeapException("not implemented");
+ final long dataBlockPosition;
+ final LeafPage leafPage = leafPage(root, dataRecordIdentifier);
+ if (leafPage == null) {
+ dataBlockPosition = -1L;
+ } else {
+ dataBlockPosition = leafPage
+ .getDataBlockPosition(dataRecordIdentifier);
+ }
+ return dataBlockPosition;
}
- @Override
- protected Iterator<DataRecordIdentifier> dataRecordIteratorImpl()
+ private IDataBlock dataBlock(final DataRecordIdentifier dataRecordIdentifier)
throws HeapException {
- // FIXMELUC ________to implement
- throw new HeapException("not implemented");
+ final IPageRecordable root = btreePlusElementMgr.getRoot();
+ return dataBlock(root, dataRecordIdentifier);
}
+ private IDataBlock dataBlock(final IPageRecordable root,
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ final IDataBlock dataBlock;
+ final LeafPage leafPage = leafPage(root, dataRecordIdentifier);
+ if (leafPage == null) {
+ dataBlock = null;
+ } else {
+ final long dataBlockPosition = leafPage
+ .getDataBlockPosition(dataRecordIdentifier);
+ final int indexinLeafPage = leafPage.getIndex();
+ dataBlock = btreePlusElementMgr.getDataBlock(dataBlockPosition);
+ dataBlock.setParent(leafPage, indexinLeafPage);
+ }
+ return dataBlock;
+ }
+
+ private LeafPage leafPage(final IPageRecordable root,
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ IPageRecordable page;
+ if (root == null) {
+ page = null;
+ } else {
+ page = root;
+ while (!EnumRecordType.LEAF_PAGE.equals(page)) {
+ final NonTerminalPage nonTerminalPage = (NonTerminalPage) page;
+ final int index = nonTerminalPage
+ .getIndex(dataRecordIdentifier);
+ final long pagePosition = nonTerminalPage.getPagePointer(index);
+ page = btreePlusElementMgr.getPage(pagePosition, page, index);
+ }
+ }
+ return (LeafPage) page;
+ }
+
@Override
protected long heapSizeImpl() throws HeapException {
return btreePlusElementMgr.heapSize();
@@ -371,8 +463,26 @@
return btreePlusElementMgr.usedSize();
}
+ // --------------------------------------------
+
@Fortest
@Override
+ protected Set<DataRecordIdentifier> getDataRecordIdentifierSetImpl()
+ throws HeapException {
+ // FIXMELUC ________to implement
+ throw new HeapException("not implemented");
+ }
+
+ @Fortest
+ @Override
+ protected Iterator<DataRecordIdentifier> dataRecordIteratorImpl()
+ throws HeapException {
+ // FIXMELUC ________to implement
+ throw new HeapException("not implemented");
+ }
+
+ @Fortest
+ @Override
public long getRecordPositionInfile(final DataRecordIdentifier identifier)
throws HeapException {
return btreePlusElementMgr.getRecordPositionInfile(identifier);
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-28 22:10:12 UTC (rev 3037)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-29 04:09:15 UTC (rev 3038)
@@ -324,4 +324,9 @@
return pageRecordable instanceof ILeafPage
|| pageRecordable instanceof NonTerminalPage;
}
+
+ public void freePage(IPageRecord pageRecord) {
+ // FIXMELUC _______________to implement
+
+ }
}
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java 2012-04-28 22:10:12 UTC (rev 3037)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java 2012-04-29 04:09:15 UTC (rev 3038)
@@ -66,26 +66,27 @@
LeafPage leafPage = new LeafPage();
leafPage.setPageRecord(PAGE_RECORD);
addToLeafPage(leafPage, 1000/* position */, 10/* key value */, 10, 1);
+ checkContent(leafPage,
+ /**/new int[] { 10 },
+ /**/new long[] { 1000 });
addToLeafPage(leafPage, 2000/* position */, 5/* key value */, 10, 2);
+ checkContent(leafPage,
+ /**/new int[] { 5, 10 },
+ /**/new long[] { 2000, 1000 });
addToLeafPage(leafPage, 3000/* position */, 15/* key value */, 15, 3);
+ checkContent(leafPage,
+ /**/new int[] { 5, 10, 15 },
+ /**/new long[] { 2000, 1000, 3000 });
addToLeafPage(leafPage, 4000/* position */, 7/* key value */, 15, 4);
+ checkContent(leafPage,
+ /**/new int[] { 5, 7, 10, 15 },
+ /**/new long[] { 2000, 4000, 1000, 3000 });
addToLeafPage(leafPage, 5000/* position */, 17/* key value */, 17, 5);
- assertEquals("bad #0 key", new DataRecordIdentifier(5),
- leafPage.getKey(0));
- assertEquals("bad #0 position", 2000, leafPage.getBlockPointer(0));
- assertEquals("bad #1 key", new DataRecordIdentifier(7),
- leafPage.getKey(1));
- assertEquals("bad #1 position", 4000, leafPage.getBlockPointer(1));
- assertEquals("bad #2 key", new DataRecordIdentifier(10),
- leafPage.getKey(2));
- assertEquals("bad #2 position", 1000, leafPage.getBlockPointer(2));
- assertEquals("bad #3 key", new DataRecordIdentifier(15),
- leafPage.getKey(3));
- assertEquals("bad #3 position", 3000, leafPage.getBlockPointer(3));
- assertEquals("bad #4 key", new DataRecordIdentifier(17),
- leafPage.getKey(4));
- assertEquals("bad #4 position", 5000, leafPage.getBlockPointer(4));
+ checkContent(leafPage,
+ /**/new int[] { 5, 7, 10, 15, 17 },
+ /**/new long[] { 2000, 4000, 1000, 3000, 5000 });
+ // test no more add possible
final int maxNumberOfEntries = maxNumberOfEntries();
final MockDataBlock dataBlock = new MockDataBlock();
while (leafPage.getNumberOfKeyEntries() != maxNumberOfEntries) {
@@ -221,6 +222,117 @@
}
}
+ public void testRemove() throws HeapException {
+ final LeafPage leafPage = new LeafPage();
+ addToLeafPage(leafPage,
+ /**/new int[] { 5, 7, 10, 15, 17 },
+ /**/new long[] { 2000, 4000, 1000, 3000, 5000 });
+
+ leafPage.remove(0);
+ checkContent(leafPage,
+ /**/new int[] { 7, 10, 15, 17 },
+ /**/new long[] { 4000, 1000, 3000, 5000 });
+
+ leafPage.remove(3);
+ checkContent(leafPage,
+ /**/new int[] { 7, 10, 15 },
+ /**/new long[] { 4000, 1000, 3000 });
+
+ leafPage.remove(1);
+ checkContent(leafPage,
+ /**/new int[] { 7, 15 },
+ /**/new long[] { 4000, 3000 });
+ }
+
+ public void testEquilibrateMerge() throws HeapException {
+ final LeafPage leftLeafPage = new LeafPage();
+ final LeafPage rightLeafPage = new LeafPage();
+ addToLeafPage(leftLeafPage,
+ /**/new int[] { 5, 7, 10, 15, 17 },
+ /**/new long[] { 2000, 4000, 1000, 3000, 5000 });
+ addToLeafPage(rightLeafPage,
+ /**/new int[] { 50, 70, 100, 150, 170 },
+ /**/new long[] { 20000, 40000, 10000, 30000, 50000 });
+ assertTrue("must merge", leftLeafPage.equilibrate(rightLeafPage));
+ checkContent(leftLeafPage,
+ /**/new int[] { 5, 7, 10, 15, 17, 50, 70, 100, 150, 170 },
+ /**/new long[] { 2000, 4000, 1000, 3000, 5000, 20000, 40000, 10000,
+ 30000, 50000 });
+ }
+
+ public void testEquilibrateRightToLeft() throws HeapException {
+ final LeafPage leftLeafPage = new LeafPage();
+ addToLeafPage(leftLeafPage, createKeys(1, 128 + 32),
+ createPointers(1000, 128 + 32));
+ final LeafPage rightLeafPage = new LeafPage();
+ addToLeafPage(rightLeafPage, createKeys(1 + 128 + 32, 128 + 64),
+ createPointers(1000 + 128 + 32, 128 + 64));
+ assertFalse("must not merge", leftLeafPage.equilibrate(rightLeafPage));
+ checkContent(leftLeafPage, createKeys(1, 176),
+ createPointers(1000, 176));
+ checkContent(rightLeafPage, createKeys(1 + 176, 176),
+ createPointers(1000 + 176, 176));
+ }
+
+ public void testEquilibrateLeftToRight() throws HeapException {
+ final LeafPage leftLeafPage = new LeafPage();
+ addToLeafPage(leftLeafPage, createKeys(1, 128 + 64),
+ createPointers(1000, 128 + 64));
+ final LeafPage rightLeafPage = new LeafPage();
+ addToLeafPage(rightLeafPage, createKeys(1 + 128 + 64, 128 + 32),
+ createPointers(1000 + 128 + 64, 128 + 32));
+ assertFalse("must not merge", leftLeafPage.equilibrate(rightLeafPage));
+ checkContent(leftLeafPage, createKeys(1, 176),
+ createPointers(1000, 176));
+ checkContent(rightLeafPage, createKeys(1 + 176, 176),
+ createPointers(1000 + 176, 176));
+ }
+
+ private int[] createKeys(final int start, final int length) {
+ final int[] keys = new int[length];
+ int value = start;
+ for (int index = 0; index < length; index++) {
+ keys[index] = value++;
+ }
+ return keys;
+ }
+
+ private long[] createPointers(final long start, final int length) {
+ final long[] pointers = new long[length];
+ long value = start;
+ for (int index = 0; index < length; index++) {
+ pointers[index] = value++;
+ }
+ return pointers;
+ }
+
+ private void checkContent(final LeafPage leafPage, final int[] keys,
+ final long[] pointers) {
+ int numberOfKeyEntries = leafPage.getNumberOfKeyEntries();
+ assertEquals("bad number of entries", keys.length, numberOfKeyEntries);
+ assertEquals("bad number of entries", pointers.length,
+ numberOfKeyEntries);
+ for (int index = 0; index < keys.length; index++) {
+ assertEquals("bad #" + index + " key", new DataRecordIdentifier(
+ keys[index]), leafPage.getKey(index));
+ assertEquals("bad #" + index + " position", pointers[index],
+ leafPage.getBlockPointer(index));
+ }
+ assertEquals("bad last key", keys[numberOfKeyEntries - 1],
+ leafPage.getLastKey().value);
+ }
+
+ private void addToLeafPage(final LeafPage leafPage, final int[] keys,
+ final long[] pointers) throws HeapException {
+ for (int index = 0; index < keys.length; index++) {
+ MockDataBlock dataBlock = new MockDataBlock();
+ dataBlock.setPosition(pointers[index]);
+ DataRecordIdentifier dataRecordIdentifier = new DataRecordIdentifier(
+ keys[index]);
+ leafPage.add(dataRecordIdentifier, dataBlock);
+ }
+ }
+
private int byteSize(final int numberOfKeyEntries) {
int byteSize = 1/* byte size for record type */+
/**/4/* int size for number of entries */+
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java 2012-04-28 22:10:12 UTC (rev 3037)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java 2012-04-29 04:09:15 UTC (rev 3038)
@@ -78,8 +78,8 @@
nonTerminalPage.setEntry(1, leafPageB.getPositionInFile(), null);
nonTerminalPage.updateByteSize();
- checkState(nonTerminalPage, new DataRecordIdentifier[] { key10 },
- new long[] { pageAPositionInFile, pageBPositionInFile });
+ checkState(nonTerminalPage, new int[] { 10 }, new long[] {
+ pageAPositionInFile, pageBPositionInFile });
assertEquals("bad key 9 index", 0,
nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
assertEquals("bad key 11 index", 1,
@@ -94,9 +94,8 @@
leafPageA.setInParentIndex(0);
nonTerminalPage.add(leafPageA, leafPageC);
- checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key10 },
- new long[] { pageAPositionInFile, pageCPositionInFile,
- pageBPositionInFile });
+ checkState(nonTerminalPage, new int[] { 5, 10 }, new long[] {
+ pageAPositionInFile, pageCPositionInFile, pageBPositionInFile });
assertEquals("bad key 4 index", 0,
nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
assertEquals("bad key 9 index", 1,
@@ -112,9 +111,9 @@
leafPageB.setLastKey(key15);
leafPageB.setInParentIndex(2);
nonTerminalPage.add(leafPageB, leafPageD);
- checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key10,
- key15 }, new long[] { pageAPositionInFile, pageCPositionInFile,
- pageBPositionInFile, pageDPositionInFile });
+ checkState(nonTerminalPage, new int[] { 5, 10, 15 }, new long[] {
+ pageAPositionInFile, pageCPositionInFile, pageBPositionInFile,
+ pageDPositionInFile });
assertEquals("bad key 4 index", 0,
nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
assertEquals("bad key 9 index", 1,
@@ -132,10 +131,9 @@
leafPageC.setLastKey(key7);
leafPageC.setInParentIndex(1);
nonTerminalPage.add(leafPageC, leafPageE);
- checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key7,
- key10, key15 }, new long[] { pageAPositionInFile,
- pageCPositionInFile, pageEPositionInFile, pageBPositionInFile,
- pageDPositionInFile });
+ checkState(nonTerminalPage, new int[] { 5, 7, 10, 15 }, new long[] {
+ pageAPositionInFile, pageCPositionInFile, pageEPositionInFile,
+ pageBPositionInFile, pageDPositionInFile });
assertEquals("bad key 4 index", 0,
nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
assertEquals("bad key 6 index", 1,
@@ -155,10 +153,9 @@
leafPageD.setLastKey(key17);
leafPageD.setInParentIndex(4);
nonTerminalPage.add(leafPageD, leafPageF);
- checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key7,
- key10, key15, key17 }, new long[] { pageAPositionInFile,
- pageCPositionInFile, pageEPositionInFile, pageBPositionInFile,
- pageDPositionInFile, pageFPositionInFile });
+ checkState(nonTerminalPage, new int[] { 5, 7, 10, 15, 17 }, new long[] {
+ pageAPositionInFile, pageCPositionInFile, pageEPositionInFile,
+ pageBPositionInFile, pageDPositionInFile, pageFPositionInFile });
assertEquals("bad key 4 index", 0,
nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
assertEquals("bad key 6 index", 1,
@@ -219,8 +216,8 @@
nonTerminalPage.setEntry(1, pageB.getPositionInFile(), null);
nonTerminalPage.updateByteSize();
- checkState(nonTerminalPage, new DataRecordIdentifier[] { key10 },
- new long[] { pageAPositionInFile, pageBPositionInFile });
+ checkState(nonTerminalPage, new int[] { 10 }, new long[] {
+ pageAPositionInFile, pageBPositionInFile });
assertEquals("bad key 9 index", 0,
nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
assertEquals("bad key 11 index", 1,
@@ -233,9 +230,8 @@
final DataRecordIdentifier key5 = new DataRecordIdentifier(5);
pageA.setInParentIndex(0);
nonTerminalPage.add(pageA, key5, pageC);
- checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key10 },
- new long[] { pageAPositionInFile, pageCPositionInFile,
- pageBPositionInFile });
+ checkState(nonTerminalPage, new int[] { 5, 10 }, new long[] {
+ pageAPositionInFile, pageCPositionInFile, pageBPositionInFile });
assertEquals("bad key 4 index", 0,
nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
assertEquals("bad key 9 index", 1,
@@ -251,9 +247,9 @@
final DataRecordIdentifier key15 = new DataRecordIdentifier(15);
pageB.setInParentIndex(2);
nonTerminalPage.add(pageB, key15, pageD);
- checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key10,
- key15 }, new long[] { pageAPositionInFile, pageCPositionInFile,
- pageBPositionInFile, pageDPositionInFile });
+ checkState(nonTerminalPage, new int[] { 5, 10, 15 }, new long[] {
+ pageAPositionInFile, pageCPositionInFile, pageBPositionInFile,
+ pageDPositionInFile });
assertEquals("bad key 4 index", 0,
nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
assertEquals("bad key 9 index", 1,
@@ -270,10 +266,9 @@
final DataRecordIdentifier key7 = new DataRecordIdentifier(7);
pageC.setInParentIndex(1);
nonTerminalPage.add(pageC, key7, pageE);
- checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key7,
- key10, key15 }, new long[] { pageAPositionInFile,
- pageCPositionInFile, pageEPositionInFile, pageBPositionInFile,
- pageDPositionInFile });
+ checkState(nonTerminalPage, new int[] { 5, 7, 10, 15 }, new long[] {
+ pageAPositionInFile, pageCPositionInFile, pageEPositionInFile,
+ pageBPositionInFile, pageDPositionInFile });
assertEquals("bad key 4 index", 0,
nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
assertEquals("bad key 6 index", 1,
@@ -292,10 +287,9 @@
final DataRecordIdentifier key17 = new DataRecordIdentifier(17);
pageD.setInParentIndex(4);
nonTerminalPage.add(pageD, key17, pageF);
- checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key7,
- key10, key15, key17 }, new long[] { pageAPositionInFile,
- pageCPositionInFile, pageEPositionInFile, pageBPositionInFile,
- pageDPositionInFile, pageFPositionInFile });
+ checkState(nonTerminalPage, new int[] { 5, 7, 10, 15, 17 }, new long[] {
+ pageAPositionInFile, pageCPositionInFile, pageEPositionInFile,
+ pageBPositionInFile, pageDPositionInFile, pageFPositionInFile });
assertEquals("bad key 4 index", 0,
nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
assertEquals("bad key 6 index", 1,
@@ -343,13 +337,7 @@
public void testSplit() throws HeapException {
final int maxNumberOfEntries = maxNumberOfEntries() + 1;
- final NonTerminalPage nonTerminalPage = new NonTerminalPage(
- maxNumberOfEntries);
- nonTerminalPage.setPageRecord(PAGE_RECORD);
- for (int index = 0; index < maxNumberOfEntries; index++) {
- nonTerminalPage.setEntry(index, index * 1000,
- new DataRecordIdentifier(index));
- }
+ final NonTerminalPage nonTerminalPage = createFilledNonterminalPage(maxNumberOfEntries);
nonTerminalPage.setEntry(maxNumberOfEntries, maxNumberOfEntries * 1000,
null);
nonTerminalPage.updateByteSize();
@@ -391,6 +379,19 @@
index * 1000, rightPage.getPagePointer(rightNumberOfEntries));
}
+ private NonTerminalPage createFilledNonterminalPage(
+ final int numberOfEntries) throws HeapException {
+ final NonTerminalPage nonTerminalPage = new NonTerminalPage(
+ numberOfEntries);
+ nonTerminalPage.setPageRecord(PAGE_RECORD);
+ for (int index = 0; index < numberOfEntries; index++) {
+ nonTerminalPage.setEntry(index, index * 1000,
+ new DataRecordIdentifier(index));
+ }
+ nonTerminalPage.setEntry(numberOfEntries, numberOfEntries * 1000, null);
+ return nonTerminalPage;
+ }
+
public void testSetParentPage() throws HeapException {
final NonTerminalPage nonTerminalPage = new NonTerminalPage();
final IPageRecordable parentPage = new NonTerminalPage();
@@ -401,8 +402,28 @@
nonTerminalPage.getInParentIndex());
}
+ public void testRemove() throws HeapException {
+ int numberOfEntries = 10;
+ final NonTerminalPage nonTerminalPage = createFilledNonterminalPage(numberOfEntries);
+ nonTerminalPage.updateByteSize();
+ nonTerminalPage.remove(0);
+ checkState(nonTerminalPage,
+ /**/new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+ /**/new long[] { 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000,
+ 10000 });
+ nonTerminalPage.remove(8);
+ checkState(nonTerminalPage,
+ /**/new int[] { 1, 2, 3, 4, 5, 6, 7, 8 },
+ /**/new long[] { 1000, 2000, 3000, 4000, 5000, 6000, 7000,
+ 8000, 10000 });
+ nonTerminalPage.remove(3);
+ checkState(nonTerminalPage,
+ /**/new int[] { 1, 2, 3, 5, 6, 7, 8 },
+ /**/new long[] { 1000, 2000, 3000, 5000, 6000, 7000, 8000, 10000 });
+ }
+
private void checkState(final NonTerminalPage nonTerminalPage,
- final DataRecordIdentifier[] keys, final long[] pointers) {
+ final int[] keys, final long[] pointers) {
final int numberOfEntries = keys.length;
assertEquals("bad byte size", byteSize(numberOfEntries),
nonTerminalPage.getByteSize());
@@ -410,9 +431,10 @@
numberOfEntries, nonTerminalPage.getNumberOfKeyEntries());
for (int index = 0; index < numberOfEntries; index++) {
assertEquals("bad index", index,
- nonTerminalPage.getIndex(keys[index]));
+ nonTerminalPage.getIndex(new DataRecordIdentifier(
+ keys[index])));
assertEquals("bad key #0", keys[index],
- nonTerminalPage.getKey(index));
+ nonTerminalPage.getKey(index).value);
assertEquals("bad #" + index + " page pointer", pointers[index],
nonTerminalPage.getPagePointer(index));
}
@@ -439,7 +461,7 @@
/**/4/* int size for crc32 */+
/**/numberOfKeyEntries * 8/* key entries */+
/**/(numberOfKeyEntries + 1) * 8/* pointers entries */;
- // FIXMELUC ______speedup if long value key
+ // FIXMELUC ________speedup if long value key
return xbyteSize;
}
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java 2012-04-28 22:10:12 UTC (rev 3037)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java 2012-04-29 04:09:15 UTC (rev 3038)
@@ -26,6 +26,7 @@
import net.sf.joafip.NoStorableAccess;
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.btreeplus.entity.IDataBlock;
+import net.sf.joafip.btreeplus.entity.LeafPage;
import net.sf.joafip.kvstore.service.HeapException;
/**
@@ -99,4 +100,19 @@
public int getIndexInDataBlockPage() {
return 0;
}
+
+ @Override
+ public void setParent(final LeafPage parentLeafPage,
+ final int indexInLeafPage) {
+ }
+
+ @Override
+ public LeafPage getParentLeafPage() {
+ return null;
+ }
+
+ @Override
+ public int getIndexInLeafPage() {
+ return 0;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-29 04:09:21
|
Revision: 3038
http://joafip.svn.sourceforge.net/joafip/?rev=3038&view=rev
Author: luc_peuvrier
Date: 2012-04-29 04:09:15 +0000 (Sun, 29 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. leaf page equilibrate and non terminal page remove added, tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-28 22:10:19
|
Revision: 3037
http://joafip.svn.sourceforge.net/joafip/?rev=3037&view=rev
Author: luc_peuvrier
Date: 2012-04-28 22:10:12 +0000 (Sat, 28 Apr 2012)
Log Message:
-----------
for test method reorganization
Modified Paths:
--------------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-28 22:10:18
|
Revision: 3037
http://joafip.svn.sourceforge.net/joafip/?rev=3037&view=rev
Author: luc_peuvrier
Date: 2012-04-28 22:10:12 +0000 (Sat, 28 Apr 2012)
Log Message:
-----------
for test method reorganization
Modified Paths:
--------------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java 2012-04-28 10:57:45 UTC (rev 3036)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java 2012-04-28 22:10:12 UTC (rev 3037)
@@ -20,6 +20,7 @@
import java.util.Iterator;
import java.util.Set;
+import net.sf.joafip.Fortest;
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.logger.JoafipLogger;
@@ -613,44 +614,6 @@
protected abstract long usedSizeImpl() throws HeapException;
- @Override
- public Set<DataRecordIdentifier> getDataRecordIdentifierSet()
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return getDataRecordIdentifierSetImpl();
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected abstract Set<DataRecordIdentifier> getDataRecordIdentifierSetImpl()
- throws HeapException;
-
- @Override
- public Iterator<DataRecordIdentifier> dataRecordIterator()
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return dataRecordIteratorImpl();
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected abstract Iterator<DataRecordIdentifier> dataRecordIteratorImpl()
- throws HeapException;
-
/**
* assert the data management service is started
*
@@ -697,4 +660,49 @@
}
return builder.toString();
}
+
+ // ------------------------------------------
+
+ @Fortest
+ @Override
+ public Set<DataRecordIdentifier> getDataRecordIdentifierSet()
+ throws HeapException {
+ try {
+ // ASSERTX
+ assert assertStarted();
+ return getDataRecordIdentifierSetImpl();
+ } catch (HeapException exception) {
+ closeHeapManagerAfterException();
+ throw exception;
+ } catch (RuntimeException exception) {
+ closeHeapManagerAfterException();
+ throw exception;
+ }
+ }
+
+ @Fortest
+ protected abstract Set<DataRecordIdentifier> getDataRecordIdentifierSetImpl()
+ throws HeapException;
+
+ @Fortest
+ @Override
+ public Iterator<DataRecordIdentifier> dataRecordIterator()
+ throws HeapException {
+ try {
+ // ASSERTX
+ assert assertStarted();
+ return dataRecordIteratorImpl();
+ } catch (HeapException exception) {
+ closeHeapManagerAfterException();
+ throw exception;
+ } catch (RuntimeException exception) {
+ closeHeapManagerAfterException();
+ throw exception;
+ }
+ }
+
+ @Fortest
+ protected abstract Iterator<DataRecordIdentifier> dataRecordIteratorImpl()
+ throws HeapException;
+
}
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java 2012-04-28 10:57:45 UTC (rev 3036)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java 2012-04-28 22:10:12 UTC (rev 3037)
@@ -334,10 +334,23 @@
@Fortest
Iterator<DataRecordIdentifier> dataRecordIterator() throws HeapException;
+ /**
+ * for test purpose<br>
+ *
+ * @param identifier
+ * @return
+ * @throws HeapException
+ */
@Fortest
long getRecordPositionInfile(DataRecordIdentifier identifier)
throws HeapException;
+ /**
+ * for test purpose<br>
+ *
+ * @return
+ * @throws HeapException
+ */
@Fortest
long getLastRecordPositionInFile() throws HeapException;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-28 10:57:51
|
Revision: 3036
http://joafip.svn.sourceforge.net/joafip/?rev=3036&view=rev
Author: luc_peuvrier
Date: 2012-04-28 10:57:45 +0000 (Sat, 28 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. BtreePlusElementMgr all tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-28 10:57:51
|
Revision: 3036
http://joafip.svn.sourceforge.net/joafip/?rev=3036&view=rev
Author: luc_peuvrier
Date: 2012-04-28 10:57:45 +0000 (Sat, 28 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. BtreePlusElementMgr all tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java 2012-04-28 07:54:02 UTC (rev 3035)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java 2012-04-28 10:57:45 UTC (rev 3036)
@@ -55,6 +55,7 @@
@NoStorableAccess
public class BtreePlusElementMgrTest extends AbstractJoafipCommonTestCase {
+ private static final String BAD_VALUE = "bad value";
private static final String BAD_LAST_RECORD_POSITION = "bad last record position";
private static final String BAD_RECORD_POSITION = "bad record position";
private static final String MUST_BE_STORED = "must be stored";
@@ -318,8 +319,37 @@
return data;
}
- public void testDataRecordIdentifier() {
+ public void testDataRecordIdentifier() throws HeapException {
+ btreePlusElementMgr.openTransaction();
+ long dataRecordIdentifier = btreePlusElementMgr
+ .getNextFreeDataRecordIdentifier();
+ assertEquals(BAD_VALUE, 0L, dataRecordIdentifier);
+ dataRecordIdentifier = btreePlusElementMgr.getNewDataRecordIdentifier();
+ assertEquals(BAD_VALUE, 0L, dataRecordIdentifier);
+ dataRecordIdentifier = btreePlusElementMgr
+ .getNextFreeDataRecordIdentifier();
+ assertEquals(BAD_VALUE, 1L, dataRecordIdentifier);
+ dataRecordIdentifier = btreePlusElementMgr.getNewDataRecordIdentifier();
+ assertEquals(BAD_VALUE, 1L, dataRecordIdentifier);
+ btreePlusElementMgr.closeTransaction();
+
+ btreePlusElementMgr.openTransaction();
+ dataRecordIdentifier = btreePlusElementMgr
+ .getNextFreeDataRecordIdentifier();
+ assertEquals(BAD_VALUE, 2L, dataRecordIdentifier);
+ dataRecordIdentifier = btreePlusElementMgr.getNewDataRecordIdentifier();
+ assertEquals(BAD_VALUE, 2L, dataRecordIdentifier);
+ btreePlusElementMgr.closeTransaction();
+
+ btreePlusElementMgr.openTransaction();
+ btreePlusElementMgr.setNextFreeDataRecordIdentifier(1000);
+ dataRecordIdentifier = btreePlusElementMgr
+ .getNextFreeDataRecordIdentifier();
+ assertEquals(BAD_VALUE, 1000L, dataRecordIdentifier);
+ dataRecordIdentifier = btreePlusElementMgr.getNewDataRecordIdentifier();
+ assertEquals(BAD_VALUE, 1000L, dataRecordIdentifier);
+ btreePlusElementMgr.closeTransaction();
}
public HeaderPage getHeapHeader() throws HeapException {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-28 07:54:09
|
Revision: 3035
http://joafip.svn.sourceforge.net/joafip/?rev=3035&view=rev
Author: luc_peuvrier
Date: 2012-04-28 07:54:02 +0000 (Sat, 28 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. BtreePlusElementMgr test in development, added data block tests
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/DataBlockPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/TestDataBlockContext.java
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java 2012-04-27 20:29:42 UTC (rev 3034)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java 2012-04-28 07:54:02 UTC (rev 3035)
@@ -115,7 +115,7 @@
}
@Override
- public void setNextFreeDataBlockPosition(
+ public void setNextFreeDataBlockPositionOfFree(
final long nextFreeDataBlockPosition) throws HeapException {
data[0] = (byte) (nextFreeDataBlockPosition >> 56);
data[1] = (byte) (nextFreeDataBlockPosition >> 48);
@@ -129,7 +129,7 @@
}
@Override
- public long getNextFreeDataBlockPosition() {
+ public long getNextFreeDataBlockPositionOfFree() {
return
/**/((((long) data[0]) & 0xff) << 56) |
/**/((((long) data[1]) & 0xff) << 48) |
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java 2012-04-27 20:29:42 UTC (rev 3034)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java 2012-04-28 07:54:02 UTC (rev 3035)
@@ -139,10 +139,11 @@
public void setAllFree() throws HeapException {
long nextPosition = getPositionInFile() + HEAD_SIZE + dataBlockDataSize;
for (int index = 0; index < dataBlocks.length - 1; index++) {
- dataBlocks[index].setNextFreeDataBlockPosition(nextPosition);
+ dataBlocks[index].setNextFreeDataBlockPositionOfFree(nextPosition);
nextPosition += dataBlockDataSize;
}
- dataBlocks[dataBlocks.length - 1].setNextFreeDataBlockPosition(-1L);
+ dataBlocks[dataBlocks.length - 1]
+ .setNextFreeDataBlockPositionOfFree(-1L);
setValueIsChangedValueToSave();
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java 2012-04-27 20:29:42 UTC (rev 3034)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java 2012-04-28 07:54:02 UTC (rev 3035)
@@ -38,10 +38,22 @@
byte[] getData();
- void setNextFreeDataBlockPosition(long nextFreeDataBlockPosition)
+ /**
+ * the next free data block position is wrote on data, must be call only if
+ * this is a free data block
+ *
+ * @param nextFreeDataBlockPosition
+ * @throws HeapException
+ */
+ void setNextFreeDataBlockPositionOfFree(long nextFreeDataBlockPosition)
throws HeapException;
- long getNextFreeDataBlockPosition();
+ /**
+ * make sense to be call only if this is a free data block
+ *
+ * @return next free data block position
+ */
+ long getNextFreeDataBlockPositionOfFree();
byte[] getDataHolder();
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java 2012-04-27 20:29:42 UTC (rev 3034)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java 2012-04-28 07:54:02 UTC (rev 3035)
@@ -57,4 +57,6 @@
@Override
boolean isValueChangedToSave();
+ int getNumberOfPage();
+
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java 2012-04-27 20:29:42 UTC (rev 3034)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java 2012-04-28 07:54:02 UTC (rev 3035)
@@ -67,6 +67,11 @@
}
@Override
+ public int getNumberOfPage() {
+ return pageRecordable.getNumberOfPage();
+ }
+
+ @Override
public long getPreviousRecordPositionInFile() throws HeapException {
return -1L;
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-27 20:29:42 UTC (rev 3034)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-28 07:54:02 UTC (rev 3035)
@@ -224,9 +224,11 @@
*/
public IDataBlock getDataBlock(final long dataBlockPosition)
throws HeapException {
- DataBlockPage dataBlockPage = (DataBlockPage) heapElementManager
+ final PageRecord pageRecord = (PageRecord) heapElementManager
.readHeapFileDataRecord(dataBlockPosition
& PageConstant.START_PAGE_POSITION_MASK);
+ final DataBlockPage dataBlockPage = (DataBlockPage) pageRecord
+ .getPageRecordable();
final IDataBlock datablock = dataBlockPage
.getDataBlock(dataBlockPosition);
return datablock;
@@ -278,14 +280,14 @@
final IDataBlock dataBlock;
if (freeDataBlockPosition == -1L) {
DataBlockPage dataBlockPage = new DataBlockPage(bits);
- appendPageRecordable(dataBlockPage);
+ internalAppendPageRecordable(dataBlockPage);
dataBlockPage.setAllFree();
dataBlock = dataBlockPage.getDataBlocks()[0];
} else {
dataBlock = getDataBlock(freeDataBlockPosition);
}
final long nextFreeDataBlockPosition = dataBlock
- .getNextFreeDataBlockPosition();
+ .getNextFreeDataBlockPositionOfFree();
header.setFreeDataBlockPosition(bits, nextFreeDataBlockPosition);
dataBlock.setData(data);
return dataBlock;
@@ -295,7 +297,7 @@
final byte bits = dataBlock.getBits();
final long freeDataBlockPosition = header
.getFreeDataBlockPosition(bits);
- dataBlock.setNextFreeDataBlockPosition(freeDataBlockPosition);
+ dataBlock.setNextFreeDataBlockPositionOfFree(freeDataBlockPosition);
final long position = dataBlock.getPositionInFile();
header.setFreeDataBlockPosition(bits, position);
}
@@ -304,10 +306,16 @@
throws HeapException {
// ASSERTX
assert notInternalyManagedPage(pageRecordable);
+ internalAppendPageRecordable(pageRecordable);
+ }
+
+ private void internalAppendPageRecordable(
+ final IPageRecordable pageRecordable) throws HeapException {
long pageNumber = header.getFileSizeAsNumberOfPage();
- header.setFileSizeAsNumberOfPage(pageNumber + 1);
final IPageRecord pageRecord = new PageRecord(fileForStorable,
pageRecordable, pageNumber);
+ header.setFileSizeAsNumberOfPage(pageNumber
+ + pageRecord.getNumberOfPage());
pageRecordable.setPageRecord(pageRecord);
heapElementManager.appendHeapFileRecord(pageRecord);
}
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/DataBlockPageTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/DataBlockPageTest.java 2012-04-27 20:29:42 UTC (rev 3034)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/DataBlockPageTest.java 2012-04-28 07:54:02 UTC (rev 3035)
@@ -99,7 +99,7 @@
+ ") bad free link", positionInFile,
nextFreeDataBlockPosition);
nextFreeDataBlockPosition = dataBlock
- .getNextFreeDataBlockPosition();
+ .getNextFreeDataBlockPositionOfFree();
index++;
expectedCurrentPositionInFile += blockByteSize;
}
Added: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/TestDataBlockContext.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/TestDataBlockContext.java (rev 0)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/TestDataBlockContext.java 2012-04-28 07:54:02 UTC (rev 3035)
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import java.util.ArrayList;
+import java.util.Deque;
+import java.util.List;
+
+import net.sf.joafip.NoStorableAccess;
+import net.sf.joafip.NotStorableClass;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+@NoStorableAccess
+public class TestDataBlockContext {
+
+ private static class DataBlockInfo {
+
+ private final byte contentValue;
+
+ private final long position;
+
+ public DataBlockInfo(final DataBlock dataBlock, final byte contentValue) {
+ super();
+ this.contentValue = contentValue;
+ this.position = dataBlock.getPositionInFile();
+ }
+
+ public byte getContentValue() {
+ return contentValue;
+ }
+
+ public long getPosition() {
+ return position;
+ }
+ }
+
+ private final byte bits;
+
+ private final List<DataBlockInfo> dataBlockInfoList = new ArrayList<DataBlockInfo>();
+
+ private long position;
+
+ private Deque<Long> positionDeque;
+
+ public TestDataBlockContext(final byte bits) {
+ super();
+ this.bits = bits;
+ }
+
+ public byte getBits() {
+ return bits;
+ }
+
+ public long getPosition() {
+ return position;
+ }
+
+ public void setPosition(final long position) {
+ this.position = position;
+ }
+
+ public void addDataBlock(final DataBlock dataBlock, final byte contentValue) {
+ final DataBlockInfo dataBlockInfo = new DataBlockInfo(dataBlock,
+ contentValue);
+ dataBlockInfoList.add(dataBlockInfo);
+ }
+
+ public int size() {
+ return dataBlockInfoList.size();
+ }
+
+ public byte getContentValue(final int index) {
+ return dataBlockInfoList.get(index).getContentValue();
+ }
+
+ public long getPosition(final int index) {
+ return dataBlockInfoList.get(index).getPosition();
+ }
+
+ public void setPositionDeque(final Deque<Long> positionDeque) {
+ this.positionDeque = positionDeque;
+ }
+
+ public Deque<Long> getPositionDeque() {
+ return positionDeque;
+ }
+}
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java 2012-04-27 20:29:42 UTC (rev 3034)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java 2012-04-28 07:54:02 UTC (rev 3035)
@@ -66,12 +66,12 @@
}
@Override
- public void setNextFreeDataBlockPosition(long nextFreeDataBlockPosition)
- throws HeapException {
+ public void setNextFreeDataBlockPositionOfFree(
+ long nextFreeDataBlockPosition) throws HeapException {
}
@Override
- public long getNextFreeDataBlockPosition() {
+ public long getNextFreeDataBlockPositionOfFree() {
return 0;
}
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java 2012-04-27 20:29:42 UTC (rev 3034)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java 2012-04-28 07:54:02 UTC (rev 3035)
@@ -39,6 +39,11 @@
return 0;
}
+ @Override
+ public int getNumberOfPage() {
+ return 0;
+ }
+
public void setPositionInFile(final long positionInFile) {
this.positionInFile = positionInFile;
}
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java 2012-04-27 20:29:42 UTC (rev 3034)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java 2012-04-28 07:54:02 UTC (rev 3035)
@@ -23,15 +23,25 @@
*/
package net.sf.joafip.btreeplus.service;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedList;
+
import net.sf.joafip.AbstractJoafipCommonTestCase;
import net.sf.joafip.NoStorableAccess;
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.TestException;
+import net.sf.joafip.btreeplus.entity.DataBlock;
+import net.sf.joafip.btreeplus.entity.DataBlockPage;
+import net.sf.joafip.btreeplus.entity.HeaderPage;
+import net.sf.joafip.btreeplus.entity.IDataBlock;
import net.sf.joafip.btreeplus.entity.IPageRecord;
import net.sf.joafip.btreeplus.entity.IPageRecordable;
import net.sf.joafip.btreeplus.entity.LeafPage;
import net.sf.joafip.btreeplus.entity.NonTerminalPage;
import net.sf.joafip.btreeplus.entity.PageConstant;
+import net.sf.joafip.btreeplus.entity.TestDataBlockContext;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.mock.MockHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
@@ -50,6 +60,7 @@
private static final String MUST_BE_STORED = "must be stored";
private static final String MUST_BE_NOT_STORED = "must be not stored";
private BtreePlusElementMgr btreePlusElementMgr;
+ private MockHeapElementManager heapElementManager;
public BtreePlusElementMgrTest() throws TestException {
super();
@@ -62,8 +73,9 @@
@Override
protected void setUp() throws Exception {
super.setUp();
- btreePlusElementMgr = new BtreePlusElementMgr(
- new MockHeapElementManager((int) (10 * PageConstant.PAGE_SIZE)));
+ heapElementManager = new MockHeapElementManager(
+ (int) (10000 * PageConstant.PAGE_SIZE));
+ btreePlusElementMgr = new BtreePlusElementMgr(heapElementManager);
btreePlusElementMgr.startService();
}
@@ -79,7 +91,8 @@
} catch (Exception exception) {
// ignore error
}
- btreePlusElementMgr = null;
+ btreePlusElementMgr = null;// NOPMD
+ heapElementManager = null;// NOPMD
super.tearDown();
}
@@ -151,11 +164,165 @@
btreePlusElementMgr.closeTransactionDiscardChange();
}
- public void testDataBlock() {
+ public void testDataBlock() throws HeapException {
+ TestDataBlockContext[] contextByBits = new TestDataBlockContext[PageConstant.NUMBER_OF_BLOCK_TYPE];
+ // add test when no free data record available, create new data record
+ // first add data
+ btreePlusElementMgr.openTransaction();
+ int index = 0;
+ long position = PageConstant.PAGE_SIZE;
+ for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
+ TestDataBlockContext context = new TestDataBlockContext(bits);
+ contextByBits[index] = context;
+ context.setPosition(position);
+ addDataBlock(context, bits);
+ position = context.getPosition();
+ index++;
+ }
+ btreePlusElementMgr.closeTransaction();
+
+ // add test
+ // secondly check added
+ btreePlusElementMgr.openTransaction();
+ index = 0;
+ for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
+ final TestDataBlockContext context = contextByBits[index];
+ for (int dataBlockIndex = 0; dataBlockIndex < context.size(); dataBlockIndex++) {
+ final long dataBlockPosition = context
+ .getPosition(dataBlockIndex);
+ final byte[] data = btreePlusElementMgr
+ .getData(dataBlockPosition);
+ final byte[] expectedData = createData(data.length,
+ context.getContentValue(dataBlockIndex));
+ assertTrue("bad content", Arrays.equals(expectedData, data));
+ final IDataBlock dataBlock = btreePlusElementMgr
+ .getDataBlock(dataBlockPosition);
+ assertEquals("bad data block type", bits, dataBlock.getBits());
+ }
+ index++;
+ }
+ btreePlusElementMgr.closeTransaction();
+
+ // remove test
+ btreePlusElementMgr.openTransaction();
+ index = 0;
+ for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
+ final TestDataBlockContext context = contextByBits[index];
+ final Deque<Long> positionDeque = new LinkedList<Long>();
+ for (int dataBlockIndex = 0; dataBlockIndex < context.size(); dataBlockIndex++) {
+ final long dataBlockPosition = context
+ .getPosition(dataBlockIndex);
+ final IDataBlock dataBlock = btreePlusElementMgr
+ .getDataBlock(dataBlockPosition);
+ btreePlusElementMgr.remove(dataBlock);
+ assertEquals("header not updated", dataBlockPosition,
+ getHeapHeader().getFreeDataBlockPosition(bits));
+ positionDeque.addFirst(dataBlockPosition);
+ }
+ context.setPositionDeque(positionDeque);
+ index++;
+ }
+ btreePlusElementMgr.closeTransaction();
+
+ // check removed state
+ btreePlusElementMgr.openTransaction();
+ index = 0;
+ for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
+ final TestDataBlockContext context = contextByBits[index];
+ final Deque<Long> positionDeque = context.getPositionDeque();
+ long expectedPosition = getHeapHeader().getFreeDataBlockPosition(
+ bits);
+ for (Long currentPosition : positionDeque) {
+ assertEquals("bad free position (bits=" + bits + ")",
+ expectedPosition, currentPosition.longValue());
+ expectedPosition = btreePlusElementMgr.getDataBlock(
+ expectedPosition).getNextFreeDataBlockPositionOfFree();
+ }
+ assertEquals("bad free position", -1, expectedPosition);
+ index++;
+ }
+ btreePlusElementMgr.closeTransaction();
+
+ // add test when free record available
+ btreePlusElementMgr.openTransaction();
+ index = 0;
+ for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
+ final TestDataBlockContext context = contextByBits[index];
+ final Iterator<Long> iterator = context.getPositionDeque()
+ .iterator();
+ final DataBlock dataBlock = createDataBlock(bits, (byte) 0);
+ assertEquals("bad allocation", iterator.next().longValue(),
+ dataBlock.getPositionInFile());
+ assertEquals("bad new free", iterator.next().longValue(),
+ getHeapHeader().getFirstFreeBlock(bits));
+ index++;
+ }
+ btreePlusElementMgr.closeTransaction();
}
+ private void addDataBlock(final TestDataBlockContext context,
+ final byte bits) throws HeapException {
+ long position = context.getPosition();
+ byte contentValue = 0;
+ int index = 0;
+ long nextFreeDataBlockPosition;
+ DataBlock dataBlock = createDataBlock(bits, contentValue);
+ context.addDataBlock(dataBlock, contentValue);
+ DataBlockPage dataBlockPage = dataBlock.getDataBlockPage();
+ do {
+ final long dataBlockPosition = dataBlock.getPositionInFile();
+ assertEquals("data block not in expected page (bits " + bits
+ + ", contentValue " + contentValue + ")", position,
+ dataBlockPosition & PageConstant.START_PAGE_POSITION_MASK);
+ assertEquals("bad index", index,
+ dataBlock.getIndexInDataBlockPage());
+ nextFreeDataBlockPosition = getHeapHeader().getFirstFreeBlock(bits);
+ if (nextFreeDataBlockPosition != -1L) {
+ contentValue++;
+ index++;
+ dataBlock = createDataBlock(bits, contentValue);
+ assertSame("bad data block page", dataBlockPage,
+ dataBlock.getDataBlockPage());
+ }
+ } while (nextFreeDataBlockPosition != -1L);
+ final int numberOfBlockCreated = index + 1;
+ assertEquals("number of block missmatch", numberOfBlockCreated,
+ dataBlockPage.getNumberOfBlock());
+ final int numberOfPageOfBlockPage = dataBlockPage.getNumberOfPage();
+ position += numberOfPageOfBlockPage * PageConstant.PAGE_SIZE;
+
+ contentValue++;
+ for (int count = 0; count < numberOfBlockCreated; count++) {
+ dataBlock = createDataBlock(bits, contentValue);
+ context.addDataBlock(dataBlock, contentValue);
+ contentValue++;
+ }
+ position += numberOfPageOfBlockPage * PageConstant.PAGE_SIZE;
+ context.setPosition(position);
+ }
+
+ private DataBlock createDataBlock(final byte bits, final byte contentValue)
+ throws HeapException {
+ final int dataSize = (1 << bits) * 3 / 4;
+ final byte[] data = createData(dataSize, contentValue);
+ final DataBlock dataBlock = (DataBlock) btreePlusElementMgr
+ .createDataBlock(data);
+ assertEquals("bad data block type", bits, dataBlock.getBits());
+ return dataBlock;
+ }
+
+ private byte[] createData(final int dataSize, final byte contentValue) {
+ byte[] data = new byte[dataSize];
+ Arrays.fill(data, contentValue);
+ return data;
+ }
+
public void testDataRecordIdentifier() {
}
+
+ public HeaderPage getHeapHeader() throws HeapException {
+ return (HeaderPage) heapElementManager.getHeapHeader();
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-28 07:54:08
|
Revision: 3035
http://joafip.svn.sourceforge.net/joafip/?rev=3035&view=rev
Author: luc_peuvrier
Date: 2012-04-28 07:54:02 +0000 (Sat, 28 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. BtreePlusElementMgr test in development, added data block tests
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IPageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/DataBlockPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/TestDataBlockContext.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-27 20:29:49
|
Revision: 3034
http://joafip.svn.sourceforge.net/joafip/?rev=3034&view=rev
Author: luc_peuvrier
Date: 2012-04-27 20:29:42 +0000 (Fri, 27 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. BtreePlusElementMgr test in development
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockFileForStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockHeapElementManager.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/BtreePlusTests.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/service/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusServiceTests.java
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java 2012-04-26 03:53:20 UTC (rev 3033)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java 2012-04-27 20:29:42 UTC (rev 3034)
@@ -37,7 +37,7 @@
@NotStorableClass
public class HeaderPage extends AbstractPageRecord implements IPageRecordable {
- private long fileSizeAsNumberOfPage = -1L;
+ private long fileSizeAsNumberOfPage = 1L;
/** page number of first free page. -1 means no free page */
private long pageNumberOfFirstFreePage = -1L;
@@ -96,7 +96,7 @@
public void clear() {
super.clear();
- fileSizeAsNumberOfPage = -1L;
+ fileSizeAsNumberOfPage = 1L;
pageNumberOfFirstFreePage = -1L;
rootPagePosition = -1L;
freeDataBlocks = null;
@@ -144,7 +144,11 @@
@Override
protected void unmarshallImpl() throws HeapException {
- readFileToIoBuffer((int) PageConstant.PAGE_SIZE);
+ final int read = readFileToIoBuffer((int) PageConstant.PAGE_SIZE);
+ if (read != PageConstant.PAGE_SIZE) {
+ throw new HeapException("read " + read + " for "
+ + PageConstant.PAGE_SIZE + " expected");
+ }
final EnumRecordType recordType = readRecordType();
if (!EnumRecordType.HEADER_PAGE.equals(recordType)) {
throw new HeapException(EnumRecordType.HEADER_PAGE
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java 2012-04-26 03:53:20 UTC (rev 3033)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java 2012-04-27 20:29:42 UTC (rev 3034)
@@ -67,6 +67,8 @@
public LeafPage(final int numberOfKeyEntries,
final long[] dataBlockPosition, final DataRecordIdentifier[] keys) {
super();
+ assert numberOfKeyEntries == dataBlockPosition.length
+ && numberOfKeyEntries == keys.length;
this.numberOfKeyEntries = numberOfKeyEntries;
this.dataBlockPosition = dataBlockPosition;
this.keys = keys;
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-26 03:53:20 UTC (rev 3033)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-27 20:29:42 UTC (rev 3034)
@@ -68,6 +68,8 @@
public NonTerminalPage(final int numberOfKeyEntries,
final DataRecordIdentifier[] keys, final long[] pagePosition) {
super();
+ assert numberOfKeyEntries == keys.length
+ && numberOfKeyEntries + 1 == pagePosition.length;
this.numberOfKeyEntries = numberOfKeyEntries;
this.keys = keys;
this.pagePositions = pagePosition;
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java 2012-04-26 03:53:20 UTC (rev 3033)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java 2012-04-27 20:29:42 UTC (rev 3034)
@@ -116,7 +116,11 @@
@Override
protected void unmarshallImpl() throws HeapException {
// one page is minimum size
- readFileToIoBuffer((int) PageConstant.PAGE_SIZE);
+ final int read = readFileToIoBuffer((int) PageConstant.PAGE_SIZE);
+ if (read != PageConstant.PAGE_SIZE) {
+ throw new HeapException("read " + read + " for "
+ + PageConstant.PAGE_SIZE + " expected");
+ }
recordType = readRecordType();
switch (recordType) {
case NON_TERMINAL_PAGE:
@@ -231,7 +235,12 @@
final DataBlockPage dataBlockPage = new DataBlockPage(bits);
dataBlockPage.setPageRecord(this);
final int numberOfPage = dataBlockPage.getNumberOfPage();
- readFileAppendToIoBuffer(numberOfPage * (int) PageConstant.PAGE_SIZE);
+ final int newSize = numberOfPage * (int) PageConstant.PAGE_SIZE;
+ final int totalReadSize = readFileAppendToIoBuffer(newSize);
+ if (totalReadSize != newSize) {
+ throw new HeapException("failed to get " + newSize
+ + ", total read size is " + totalReadSize);
+ }
final IDataBlock[] dataBlocks = dataBlockPage.getDataBlocks();
for (IDataBlock dataBlock : dataBlocks) {
readBytes(dataBlock.getDataHolder());
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-26 03:53:20 UTC (rev 3033)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-27 20:29:42 UTC (rev 3034)
@@ -87,7 +87,7 @@
@Override
public void setDataRecordKeyComparator(
IDataRecordKeyManager dataRecordKeyComparator) throws HeapException {
- btreePlusElementMgr.setDataRecordKeyComparator(dataRecordKeyComparator);
+ btreePlusElementMgr.setDataRecordKeyManager(dataRecordKeyComparator);
}
@Override
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-26 03:53:20 UTC (rev 3033)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-27 20:29:42 UTC (rev 3034)
@@ -28,6 +28,7 @@
import net.sf.joafip.btreeplus.entity.DataBlockPage;
import net.sf.joafip.btreeplus.entity.HeaderPage;
import net.sf.joafip.btreeplus.entity.IDataBlock;
+import net.sf.joafip.btreeplus.entity.ILeafPage;
import net.sf.joafip.btreeplus.entity.INonTerminalPage;
import net.sf.joafip.btreeplus.entity.IPageRecord;
import net.sf.joafip.btreeplus.entity.IPageRecordable;
@@ -77,10 +78,10 @@
}
}
- public void setDataRecordKeyComparator(
- final IDataRecordKeyManager dataRecordKeyComparator)
+ public void setDataRecordKeyManager(
+ final IDataRecordKeyManager dataRecordKeyManager)
throws HeapException {
- heapElementManager.setDataRecordKeyManager(dataRecordKeyComparator);
+ heapElementManager.setDataRecordKeyManager(dataRecordKeyManager);
}
public void startService() throws HeapException {
@@ -158,7 +159,8 @@
@Fortest
public long getLastRecordPositionInFile() throws HeapException {
- throw new UnsupportedOperationException("not implemented");
+ return (header.getFileSizeAsNumberOfPage() - 1)
+ * PageConstant.PAGE_SIZE;
}
public long getNextFreeDataRecordIdentifier() {
@@ -193,9 +195,13 @@
public IPageRecordable getPage(final long position,
final IPageRecordable parentPage, final int index)
throws HeapException {
- final IPageRecordable readHeapFileDataRecord = (IPageRecordable) heapElementManager
+ final PageRecord pageRecord = (PageRecord) heapElementManager
.readHeapFileDataRecord(position);
+ final IPageRecordable readHeapFileDataRecord = pageRecord
+ .getPageRecordable();
readHeapFileDataRecord.setParentPage(parentPage, index);
+ // ASSERTX
+ assert notInternalyManagedPage(readHeapFileDataRecord);
return readHeapFileDataRecord;
}
@@ -234,6 +240,7 @@
leafPage.setDataBlock(0, dataBlock);
leafPage.setNext(-1L);
leafPage.updateByteSize();
+ leafPage.setValueIsChangedValueToSave();
header.setRootPagePosition(leafPage.getPositionInFile());
}
@@ -245,6 +252,7 @@
nonTerminalPage.setEntry(1, rightLeafPage.getPositionInFile(), null);
appendPageRecordable(nonTerminalPage);
nonTerminalPage.updateByteSize();
+ nonTerminalPage.setValueIsChangedValueToSave();
header.setRootPagePosition(nonTerminalPage.getPositionInFile());
}
@@ -259,6 +267,7 @@
null);
appendPageRecordable(nonTerminalPage);
nonTerminalPage.updateByteSize();
+ nonTerminalPage.setValueIsChangedValueToSave();
header.setRootPagePosition(nonTerminalPage.getPositionInFile());
}
@@ -291,13 +300,20 @@
header.setFreeDataBlockPosition(bits, position);
}
- public void appendPageRecordable(IPageRecordable pageRecordable)
+ public void appendPageRecordable(final IPageRecordable pageRecordable)
throws HeapException {
- long pageNumber = header.getFileSizeAsNumberOfPage() + 1;
- header.setFileSizeAsNumberOfPage(pageNumber);
+ // ASSERTX
+ assert notInternalyManagedPage(pageRecordable);
+ long pageNumber = header.getFileSizeAsNumberOfPage();
+ header.setFileSizeAsNumberOfPage(pageNumber + 1);
final IPageRecord pageRecord = new PageRecord(fileForStorable,
pageRecordable, pageNumber);
pageRecordable.setPageRecord(pageRecord);
heapElementManager.appendHeapFileRecord(pageRecord);
}
+
+ private boolean notInternalyManagedPage(final IPageRecordable pageRecordable) {
+ return pageRecordable instanceof ILeafPage
+ || pageRecordable instanceof NonTerminalPage;
+ }
}
Added: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java (rev 0)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java 2012-04-27 20:29:42 UTC (rev 3034)
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.service;
+
+import net.sf.joafip.AbstractJoafipCommonTestCase;
+import net.sf.joafip.NoStorableAccess;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestException;
+import net.sf.joafip.btreeplus.entity.IPageRecord;
+import net.sf.joafip.btreeplus.entity.IPageRecordable;
+import net.sf.joafip.btreeplus.entity.LeafPage;
+import net.sf.joafip.btreeplus.entity.NonTerminalPage;
+import net.sf.joafip.btreeplus.entity.PageConstant;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.mock.MockHeapElementManager;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+@NoStorableAccess
+public class BtreePlusElementMgrTest extends AbstractJoafipCommonTestCase {
+
+ private static final String BAD_LAST_RECORD_POSITION = "bad last record position";
+ private static final String BAD_RECORD_POSITION = "bad record position";
+ private static final String MUST_BE_STORED = "must be stored";
+ private static final String MUST_BE_NOT_STORED = "must be not stored";
+ private BtreePlusElementMgr btreePlusElementMgr;
+
+ public BtreePlusElementMgrTest() throws TestException {
+ super();
+ }
+
+ public BtreePlusElementMgrTest(final String name) throws TestException {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ btreePlusElementMgr = new BtreePlusElementMgr(
+ new MockHeapElementManager((int) (10 * PageConstant.PAGE_SIZE)));
+ btreePlusElementMgr.startService();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ try {
+ btreePlusElementMgr.closeTransactionDiscardChange();
+ } catch (Exception exception) {
+ // ignore error
+ }
+ try {
+ btreePlusElementMgr.stopService();
+ } catch (Exception exception) {
+ // ignore error
+ }
+ btreePlusElementMgr = null;
+ super.tearDown();
+ }
+
+ public void testAppendPageRecordable() throws HeapException {
+ btreePlusElementMgr.openTransaction();
+ IPageRecordable pageRecordable = new LeafPage();
+ assertNull(MUST_BE_NOT_STORED, pageRecordable.getPageRecord());
+ btreePlusElementMgr.appendPageRecordable(pageRecordable);
+ pageRecordable.setValueIsChangedValueToSave();
+ IPageRecord pageRecord = pageRecordable.getPageRecord();
+ assertNotNull(MUST_BE_STORED, pageRecord);
+ assertEquals(BAD_RECORD_POSITION, PageConstant.PAGE_SIZE * 1,
+ pageRecord.getPositionInFile());
+ assertEquals(BAD_LAST_RECORD_POSITION, PageConstant.PAGE_SIZE * 1,
+ btreePlusElementMgr.getLastRecordPositionInFile());
+
+ pageRecordable = new NonTerminalPage();
+ assertNull(MUST_BE_NOT_STORED, pageRecordable.getPageRecord());
+ btreePlusElementMgr.appendPageRecordable(pageRecordable);
+ pageRecordable.setValueIsChangedValueToSave();
+ pageRecord = pageRecordable.getPageRecord();
+ assertNotNull(MUST_BE_STORED, pageRecord);
+ assertEquals(BAD_RECORD_POSITION, PageConstant.PAGE_SIZE * 2,
+ pageRecord.getPositionInFile());
+ assertEquals(BAD_LAST_RECORD_POSITION, PageConstant.PAGE_SIZE * 2,
+ btreePlusElementMgr.getLastRecordPositionInFile());
+ btreePlusElementMgr.closeTransaction();
+ assertEquals("", PageConstant.PAGE_SIZE * 3, btreePlusElementMgr
+ .getFileForStorable().getFileSize());
+
+ btreePlusElementMgr.openTransaction();
+ final int numberOfKeyEntries = 1;
+ final DataRecordIdentifier[] keys = new DataRecordIdentifier[] { new DataRecordIdentifier(
+ 0) };
+ final long[] pagePosition = new long[] { 0, 1 };
+ pageRecordable = new NonTerminalPage(numberOfKeyEntries, keys,
+ pagePosition);
+ assertNull(MUST_BE_NOT_STORED, pageRecordable.getPageRecord());
+ btreePlusElementMgr.appendPageRecordable(pageRecordable);
+ pageRecordable.setValueIsChangedValueToSave();
+ pageRecord = pageRecordable.getPageRecord();
+ assertNotNull(MUST_BE_STORED, pageRecord);
+ assertEquals(BAD_RECORD_POSITION, PageConstant.PAGE_SIZE * 3,
+ pageRecord.getPositionInFile());
+ assertEquals(BAD_LAST_RECORD_POSITION, PageConstant.PAGE_SIZE * 3,
+ btreePlusElementMgr.getLastRecordPositionInFile());
+ btreePlusElementMgr.closeTransaction();
+ assertEquals("", PageConstant.PAGE_SIZE * 4, btreePlusElementMgr
+ .getFileForStorable().getFileSize());
+
+ btreePlusElementMgr.openTransaction();
+ long position = PageConstant.PAGE_SIZE;
+ pageRecordable = btreePlusElementMgr.getPage(position, null, 0);
+ assertTrue("leaf page expected", pageRecordable instanceof LeafPage);
+ position += PageConstant.PAGE_SIZE;
+ pageRecordable = btreePlusElementMgr.getPage(position, null, 0);
+ assertTrue("non terminal page expected",
+ pageRecordable instanceof NonTerminalPage);
+ NonTerminalPage nonTerminalPage = (NonTerminalPage) pageRecordable;
+ assertEquals("bad non terminal page #1 state", 0,
+ nonTerminalPage.getNumberOfKeyEntries());
+ position += PageConstant.PAGE_SIZE;
+ pageRecordable = btreePlusElementMgr.getPage(position, null, 0);
+ assertTrue("non terminal page expected",
+ pageRecordable instanceof NonTerminalPage);
+ nonTerminalPage = (NonTerminalPage) pageRecordable;
+ assertEquals("bad non terminal page #2 state", 1,
+ nonTerminalPage.getNumberOfKeyEntries());
+ btreePlusElementMgr.closeTransactionDiscardChange();
+ }
+
+ public void testDataBlock() {
+
+ }
+
+ public void testDataRecordIdentifier() {
+
+ }
+}
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java 2012-04-26 03:53:20 UTC (rev 3033)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java 2012-04-27 20:29:42 UTC (rev 3034)
@@ -220,6 +220,11 @@
protected int readFileToIoBuffer(final int size) throws HeapException {
ioBuffer = new byte[size];
readInIoBuffer = fileForStorable.read(ioBuffer);
+ // bad test because must read when only maximum size is known
+ // if( readInIoBuffer!=size) {
+ // throw new
+ // HeapException("failed read "+size+" bytes, read "+readInIoBuffer);
+ // }
numberOfByteReadWrote = 0;
return readInIoBuffer;
}
@@ -229,16 +234,22 @@
*
* @param newSize
* ioBuffer new size
+ * @return
* @throws HeapException
*/
- protected void readFileAppendToIoBuffer(final int newSize)
+ protected int readFileAppendToIoBuffer(final int newSize)
throws HeapException {
+ final int totalRead;
if (newSize > ioBuffer.length) {
ioBuffer = Arrays.copyOf(ioBuffer, newSize);
final int appendSize = newSize - readInIoBuffer;
- fileForStorable.read(ioBuffer, readInIoBuffer/* offset */,
- appendSize/* length */);
+ final int read = fileForStorable.read(ioBuffer,
+ readInIoBuffer/* offset */, appendSize/* length */);
+ totalRead = readInIoBuffer + read;
+ } else {
+ totalRead = ioBuffer.length;
}
+ return totalRead;
}
/**
Modified: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockFileForStorable.java
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockFileForStorable.java 2012-04-26 03:53:20 UTC (rev 3033)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockFileForStorable.java 2012-04-27 20:29:42 UTC (rev 3034)
@@ -120,7 +120,9 @@
int index = offset;
int count = 0;
while (count < length && positionInFile < size) {
- data[index++] = image[(int) positionInFile++];
+ final byte value = image[(int) positionInFile++];
+ data[index++] = value;
+ count++;
}
return count;
}
Modified: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockHeapElementManager.java
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockHeapElementManager.java 2012-04-26 03:53:20 UTC (rev 3033)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockHeapElementManager.java 2012-04-27 20:29:42 UTC (rev 3034)
@@ -70,6 +70,7 @@
if (started) {
throw new HeapException("already started");
}
+ fileForStorable.open();
started = true;
}
@@ -86,6 +87,7 @@
throw new HeapException("already stopped");
}
started = false;
+ fileForStorable.close();
}
@Override
@@ -98,10 +100,19 @@
if (transactionOpen) {
throw new HeapException("transaction already openned");
}
- if (heapHeader != null) {
- heapHeader.clear();
+ cache.clear();
+ final long fileSize = getFileSize();
+ heapHeader.clear();
+ if (fileSize == 0) {
+ /* to save new header */
+ heapHeader.setValueIsChangedValueToSave();
+ heapHeader.writeToFile();
+ fileForStorable.flush();
+ fileForStorable.close();
+ fileForStorable.open();
+ } else {
+ heapHeader.readFromFile();
}
- cache.clear();
transactionOpen = true;
}
@@ -178,7 +189,6 @@
@Override
public void setHeapHeader(final IFileStorable heapHeader)
throws HeapException {
- assertTransactionOpenned();
this.heapHeader = heapHeader;
}
Modified: trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/BtreePlusTests.java
===================================================================
--- trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/BtreePlusTests.java 2012-04-26 03:53:20 UTC (rev 3033)
+++ trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/BtreePlusTests.java 2012-04-27 20:29:42 UTC (rev 3034)
@@ -27,6 +27,7 @@
import junit.framework.TestSuite;
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.btreeplus.entity.BtreePlusEntityTests;
+import net.sf.joafip.btreeplus.service.BtreePlusServiceTests;
/**
*
@@ -44,6 +45,7 @@
final TestSuite suite = new TestSuite("Test for btree plus");
// $JUnit-BEGIN$
suite.addTest(BtreePlusEntityTests.suite());
+ suite.addTest(BtreePlusServiceTests.suite());
// $JUnit-END$
return suite;
}
Added: trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusServiceTests.java
===================================================================
--- trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusServiceTests.java (rev 0)
+++ trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusServiceTests.java 2012-04-27 20:29:42 UTC (rev 3034)
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.service;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import net.sf.joafip.NotStorableClass;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+public class BtreePlusServiceTests {
+
+ public static void main(final String[] args) {
+ //
+ }
+
+ public static Test suite() {
+ final TestSuite suite = new TestSuite("Test for btree plus service");
+ // $JUnit-BEGIN$
+ suite.addTestSuite(BtreePlusElementMgrTest.class);
+ // $JUnit-END$
+ return suite;
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-27 20:29:49
|
Revision: 3034
http://joafip.svn.sourceforge.net/joafip/?rev=3034&view=rev
Author: luc_peuvrier
Date: 2012-04-27 20:29:42 +0000 (Fri, 27 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. BtreePlusElementMgr test in development
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockFileForStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockHeapElementManager.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/BtreePlusTests.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgrTest.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/service/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusServiceTests.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-26 03:53:28
|
Revision: 3033
http://joafip.svn.sourceforge.net/joafip/?rev=3033&view=rev
Author: luc_peuvrier
Date: 2012-04-26 03:53:20 +0000 (Thu, 26 Apr 2012)
Log Message:
-----------
added mock for IheapElementManager and IFileStorable
and some corrections
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractPageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/EnumRecordType.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecordable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapRecordFactory.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/TestHeapElementManager.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/BtreePlusEntityTests.java
Added Paths:
-----------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockFileForStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockHeapElementManager.java
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -23,6 +23,7 @@
*/
package net.sf.joafip.btreeplus.entity;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
@@ -31,6 +32,7 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
public abstract class AbstractElement implements IPageRecordable {
private IPageRecord pageRecord;
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractPageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractPageRecord.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractPageRecord.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -23,6 +23,7 @@
*/
package net.sf.joafip.btreeplus.entity;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.kvstore.record.entity.DataRecordKey;
import net.sf.joafip.kvstore.entity.AbstractFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
@@ -36,6 +37,7 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
public abstract class AbstractPageRecord extends AbstractFileStorable {
public AbstractPageRecord(final IFileForStorable fileForStorable,
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -25,6 +25,7 @@
import java.util.Arrays;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.kvstore.service.HeapException;
/**
@@ -32,6 +33,7 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
public class DataBlock implements IDataBlock {
private final DataBlockPage dataBlockPage;
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -23,6 +23,7 @@
*/
package net.sf.joafip.btreeplus.entity;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.kvstore.service.HeapException;
/**
@@ -30,6 +31,7 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
public class DataBlockPage extends AbstractElement {
public static final int HEAD_SIZE =
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/EnumRecordType.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/EnumRecordType.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/EnumRecordType.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -23,11 +23,14 @@
*/
package net.sf.joafip.btreeplus.entity;
+import net.sf.joafip.NotStorableClass;
+
/**
*
* @author luc peuvrier
*
*/
+@NotStorableClass
public enum EnumRecordType {
/**
*
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -23,6 +23,7 @@
*/
package net.sf.joafip.btreeplus.entity;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.kvstore.service.HeapException;
/**
@@ -30,6 +31,7 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
public class FreePage extends AbstractElement {
private final long nextFreePage;
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -25,6 +25,7 @@
import java.util.Arrays;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.kvstore.service.IFileForStorable;
@@ -33,6 +34,7 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
public class HeaderPage extends AbstractPageRecord implements IPageRecordable {
private long fileSizeAsNumberOfPage = -1L;
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -25,6 +25,7 @@
import java.util.Arrays;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
@@ -33,6 +34,7 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
public class LeafPage extends AbstractElement implements ILeafPage {
private long[] dataBlockPosition;
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -25,6 +25,7 @@
import java.util.Arrays;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
@@ -33,6 +34,7 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
public class NonTerminalPage extends AbstractElement implements
INonTerminalPage {
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -23,11 +23,14 @@
*/
package net.sf.joafip.btreeplus.entity;
+import net.sf.joafip.NotStorableClass;
+
/**
*
* @author luc peuvrier
*
*/
+@NotStorableClass
public final class PageConstant {
public final static int PAGE_BITS = 12;
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -23,6 +23,7 @@
*/
package net.sf.joafip.btreeplus.entity;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.kvstore.service.IFileForStorable;
@@ -32,6 +33,7 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
public class PageRecord extends AbstractPageRecord implements IPageRecord {
private EnumRecordType recordType;
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -28,6 +28,7 @@
import java.util.Set;
import net.sf.joafip.Fortest;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.btreeplus.entity.EnumRecordType;
import net.sf.joafip.btreeplus.entity.IDataBlock;
import net.sf.joafip.btreeplus.entity.INonTerminalPage;
@@ -48,6 +49,7 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
public class BtreePlusDataManager extends AbstractHeapDataManager {
/**
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -24,6 +24,7 @@
package net.sf.joafip.btreeplus.service;
import net.sf.joafip.Fortest;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.btreeplus.entity.DataBlockPage;
import net.sf.joafip.btreeplus.entity.HeaderPage;
import net.sf.joafip.btreeplus.entity.IDataBlock;
@@ -36,7 +37,6 @@
import net.sf.joafip.btreeplus.entity.PageRecord;
import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
-import net.sf.joafip.kvstore.record.service.HeapElementManager;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.record.service.IHeapRecordFactory;
@@ -49,6 +49,7 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
public class BtreePlusElementMgr implements IHeapRecordFactory {
private static final JoafipLogger LOGGER = JoafipLogger
@@ -116,7 +117,7 @@
@Override
public IFileStorable createHeapRecord(
- final HeapElementManager heapElementManager,
+ final IHeapElementManager heapElementManager,
final long positionInFile) throws HeapException {
assert (positionInFile & PageConstant.IN_PAGE_POSITION_MASK) == 0;
return new PageRecord(fileForStorable,
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -23,6 +23,8 @@
*/
package net.sf.joafip.btreeplus.entity.mock;
+import net.sf.joafip.NoStorableAccess;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.btreeplus.entity.IDataBlock;
import net.sf.joafip.kvstore.service.HeapException;
@@ -31,6 +33,8 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
+@NoStorableAccess
public class MockDataBlock implements IDataBlock {
private long position;
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -23,6 +23,8 @@
*/
package net.sf.joafip.btreeplus.entity.mock;
+import net.sf.joafip.NoStorableAccess;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.btreeplus.entity.EnumRecordType;
import net.sf.joafip.btreeplus.entity.ILeafPage;
import net.sf.joafip.btreeplus.entity.IPageRecord;
@@ -35,6 +37,8 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
+@NoStorableAccess
public class MockLeafPage implements ILeafPage {
private long positionInFile;
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -23,6 +23,8 @@
*/
package net.sf.joafip.btreeplus.entity.mock;
+import net.sf.joafip.NoStorableAccess;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.btreeplus.entity.EnumRecordType;
import net.sf.joafip.btreeplus.entity.INonTerminalPage;
import net.sf.joafip.btreeplus.entity.IPageRecord;
@@ -35,6 +37,8 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
+@NoStorableAccess
public class MockNonTerminalPage implements INonTerminalPage {
private long positionInFile;
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -1,8 +1,12 @@
package net.sf.joafip.btreeplus.entity.mock;
+import net.sf.joafip.NoStorableAccess;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.btreeplus.entity.IPageRecord;
import net.sf.joafip.kvstore.service.HeapException;
+@NotStorableClass
+@NoStorableAccess
public class MockPageRecord implements IPageRecord {
private long positionInFile;
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecordable.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecordable.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecordable.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -23,6 +23,8 @@
*/
package net.sf.joafip.btreeplus.entity.mock;
+import net.sf.joafip.NoStorableAccess;
+import net.sf.joafip.NotStorableClass;
import net.sf.joafip.btreeplus.entity.EnumRecordType;
import net.sf.joafip.btreeplus.entity.IPageRecord;
import net.sf.joafip.btreeplus.entity.IPageRecordable;
@@ -33,6 +35,8 @@
* @author luc peuvrier
*
*/
+@NotStorableClass
+@NoStorableAccess
public class MockPageRecordable implements IPageRecordable {
@Override
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -33,7 +33,6 @@
import net.sf.joafip.kvstore.entity.HeapFileSetup;
import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
-import net.sf.joafip.kvstore.record.service.HeapElementManager;
import net.sf.joafip.kvstore.record.service.HeapElementManagerFactory;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.record.service.IHeapElementManager;
@@ -602,7 +601,7 @@
@Override
public IFileStorable createHeapRecord(
- final HeapElementManager heapElementManager,
+ final IHeapElementManager heapElementManager,
final long positionInFile) throws HeapException {
return new HeapRecord(heapElementManager, positionInFile);
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -29,6 +29,7 @@
import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.HeapElementManager;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.record.service.IHeapRecordFactory;
import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
@@ -146,7 +147,7 @@
@Override
public IFileStorable createHeapRecord(
- final HeapElementManager heapElementManager,
+ final IHeapElementManager heapElementManager,
final long positionInFile) throws HeapException {
return new HeapRecord(heapElementManager, positionInFile);
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -24,7 +24,7 @@
import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.AbstractTestHeapElementManager;
-import net.sf.joafip.kvstore.record.service.HeapElementManager;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTNode;
import net.sf.joafip.redblacktree.service.RBTException;
@@ -443,7 +443,7 @@
@Override
public IFileStorable createHeapRecord(
- final HeapElementManager heapElementManager,
+ final IHeapElementManager heapElementManager,
final long positionInFile) throws HeapException {
return new HeapRecord(heapElementManager, positionInFile);
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -195,7 +195,7 @@
@Override
public IFileStorable createHeapRecord(
- final HeapElementManager heapElementManager,
+ final IHeapElementManager heapElementManager,
final long positionInFile) throws HeapException {
return new HeapRecord(heapElementManager, positionInFile);
}
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -185,7 +185,7 @@
IHeapRecordFactory getHeapRecordFactory();
- void setDataRecordKeyManager(IDataRecordKeyManager dataRecordKeyComparator);
+ void setDataRecordKeyManager(IDataRecordKeyManager dataRecordKeyManager);
IDataRecordKeyManager getDataRecordKeyManager();
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapRecordFactory.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapRecordFactory.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapRecordFactory.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -33,6 +33,6 @@
*/
public interface IHeapRecordFactory {
- IFileStorable createHeapRecord(HeapElementManager heapElementManager,
+ IFileStorable createHeapRecord(IHeapElementManager heapElementManager,
long positionInFile) throws HeapException;
}
Modified: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/TestHeapElementManager.java
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/TestHeapElementManager.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/TestHeapElementManager.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -252,7 +252,7 @@
@Override
public IFileStorable createHeapRecord(
- final HeapElementManager heapElementManager,
+ final IHeapElementManager heapElementManager,
final long positionInFile) throws HeapException {
return new RecordForTest(heapElementManager, positionInFile,
RECORD_SIZE, positionInFile - RECORD_SIZE);
Added: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockFileForStorable.java
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockFileForStorable.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockFileForStorable.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.kvstore.record.service.mock;
+
+import java.io.File;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.file.service.FileIOErrorException;
+import net.sf.joafip.file.service.FileIOException;
+import net.sf.joafip.kvstore.entity.ToBackupRecord;
+import net.sf.joafip.kvstore.service.FileForStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.IFileForStorable;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+public class MockFileForStorable implements IFileForStorable {
+
+ private final byte[] image;
+
+ private int size;
+
+ private boolean openned;
+
+ private long positionInFile;
+
+ public MockFileForStorable(final int maxSize) {
+ super();
+ image = new byte[maxSize];
+ size = 0;
+ }
+
+ @Override
+ public void open() throws HeapException {
+ assertClosed();
+ this.positionInFile = 0;
+ openned = true;
+ }
+
+ @Override
+ public void close() throws HeapException {
+ assertOpenned();
+ openned = false;
+ }
+
+ @Override
+ public File getFile() {
+ return new File("MOCK");
+ }
+
+ @Override
+ public void deleteFileIfExists() throws HeapException {
+ assertClosed();
+ size = 0;
+ }
+
+ @Override
+ public void deleteFileIfExistsRenaming() throws HeapException {
+ assertClosed();
+ size = 0;
+ }
+
+ @Override
+ public long getFileSize() throws HeapException {
+ return size;
+ }
+
+ @Override
+ public void flush() throws HeapException {
+ assertOpenned();
+ // no implementation
+ }
+
+ @Override
+ public void resetFileSize() throws HeapException {
+ assertOpenned();
+ size = 0;
+ }
+
+ @Override
+ public void seek(final long positionInFile) throws HeapException {
+ assertOpenned();
+ this.positionInFile = positionInFile;
+ }
+
+ @Override
+ public int read(final byte[] data) throws HeapException {
+ return read(data, 0, data.length);
+ }
+
+ @Override
+ public int read(final byte[] data, final int offset, final int length)
+ throws HeapException {
+ assertOpenned();
+ int index = offset;
+ int count = 0;
+ while (count < length && positionInFile < size) {
+ data[index++] = image[(int) positionInFile++];
+ }
+ return count;
+ }
+
+ @Override
+ public void write(final byte[] data) throws HeapException {
+ assertOpenned();
+ if (positionInFile + data.length > size) {
+ size = (int) (positionInFile + data.length);
+ if (size > image.length) {
+ throw new HeapException("out of image buffer");
+ }
+ }
+ for (int index = 0; index < data.length; index++) {
+ image[(int) positionInFile++] = data[index];
+ }
+ }
+
+ @Override
+ public void write(final ToBackupRecord toBackupRecord) throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public void copy(FileForStorable fileForStorable) throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public void copy(String fileName) throws FileIOException {
+ throw new FileIOErrorException("unsupported", new File("MOCK"), null);
+ }
+
+ @Override
+ public boolean isUseCache() {
+ return false;
+ }
+
+ @Override
+ public int getCachePageSize() {
+ return 0;
+ }
+
+ private void assertOpenned() throws HeapException {
+ if (!openned) {
+ throw new HeapException("is closed");
+ }
+ }
+
+ private void assertClosed() throws HeapException {
+ if (openned) {
+ throw new HeapException("is openned");
+ }
+ }
+}
Added: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockHeapElementManager.java
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockHeapElementManager.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockHeapElementManager.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -0,0 +1,262 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.kvstore.record.service.mock;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.kvstore.entity.IFileStorable;
+import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.record.service.IHeapRecordFactory;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.IFileForStorable;
+import net.sf.joafip.logger.JoafipLogger;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+public class MockHeapElementManager implements IHeapElementManager {
+
+ private static final JoafipLogger LOGGER = JoafipLogger
+ .getLogger(MockHeapElementManager.class);
+
+ private final IFileForStorable fileForStorable;
+
+ private boolean started;
+
+ private boolean transactionOpen;
+
+ private IDataRecordKeyManager dataRecordKeyManager;
+
+ private IHeapRecordFactory heapRecordFactory;
+
+ private IFileStorable heapHeader;
+
+ private final Map<Long, IFileStorable> cache = new TreeMap<Long, IFileStorable>();
+
+ public MockHeapElementManager(final int maxSize) {
+ super();
+ fileForStorable = new MockFileForStorable(maxSize);
+ }
+
+ @Override
+ public void startService() throws HeapException {
+ if (started) {
+ throw new HeapException("already started");
+ }
+ started = true;
+ }
+
+ @Override
+ public void stopService() throws HeapException {
+ if (isTransactionOpened()) {
+ try {
+ closeTransactionDiscardChange();
+ } catch (Exception exception) {
+ LOGGER.error("clossing transaction while stopping service");
+ }
+ }
+ if (!started) {
+ throw new HeapException("already stopped");
+ }
+ started = false;
+ }
+
+ @Override
+ public boolean isServiceStarted() {
+ return started;
+ }
+
+ @Override
+ public void openTransaction() throws HeapException {
+ if (transactionOpen) {
+ throw new HeapException("transaction already openned");
+ }
+ if (heapHeader != null) {
+ heapHeader.clear();
+ }
+ cache.clear();
+ transactionOpen = true;
+ }
+
+ @Override
+ public void closeTransaction() throws HeapException {
+ if (!transactionOpen) {
+ throw new HeapException("transaction already closed");
+ }
+ transactionOpen = false;
+ if (heapHeader.isValueChangedToSave()) {
+ heapHeader.writeToFile();
+ }
+ for (IFileStorable fileStorable : cache.values()) {
+ if (fileStorable.isValueChangedToSave()) {
+ fileStorable.writeToFile();
+ }
+ }
+ heapHeader.clear();
+ cache.clear();
+ }
+
+ @Override
+ public void closeTransactionDiscardChange() throws HeapException {
+ if (!transactionOpen) {
+ throw new HeapException("transaction already closed");
+ }
+ transactionOpen = false;
+ heapHeader.clear();
+ cache.clear();
+ }
+
+ @Override
+ public boolean isTransactionOpened() {
+ return transactionOpen;
+ }
+
+ @Override
+ public void setDataRecordKeyManager(
+ final IDataRecordKeyManager dataRecordKeyManager) {
+ this.dataRecordKeyManager = dataRecordKeyManager;
+ }
+
+ @Override
+ public IDataRecordKeyManager getDataRecordKeyManager() {
+ return dataRecordKeyManager;
+ }
+
+ @Override
+ public void setHeapRecordFactory(final IHeapRecordFactory heapRecordFactory) {
+ this.heapRecordFactory = heapRecordFactory;
+ }
+
+ @Override
+ public IHeapRecordFactory getHeapRecordFactory() {
+ return heapRecordFactory;
+ }
+
+ @Override
+ public IFileForStorable getFileForStorable() {
+ return fileForStorable;
+ }
+
+ @Override
+ public long getFileSize() throws HeapException {
+ return fileForStorable.getFileSize();
+ }
+
+ @Override
+ public void removeFiles() throws HeapException {
+ assertTransactionClosed();
+ fileForStorable.deleteFileIfExists();
+ }
+
+ @Override
+ public void setHeapHeader(final IFileStorable heapHeader)
+ throws HeapException {
+ assertTransactionOpenned();
+ this.heapHeader = heapHeader;
+ }
+
+ @Override
+ public IFileStorable getHeapHeader() throws HeapException {
+ assertTransactionOpenned();
+ return heapHeader;
+ }
+
+ @Override
+ public IFileStorable readHeapFileDataRecord(long positionInFile)
+ throws HeapException {
+ assertTransactionOpenned();
+ IFileStorable fileStorable = cache.get(positionInFile);
+ if (fileStorable == null) {
+ fileStorable = heapRecordFactory.createHeapRecord(this,
+ positionInFile);
+ cache.put(positionInFile, fileStorable);
+ fileStorable.readFromFile();
+ }
+ return fileStorable;
+ }
+
+ @Override
+ public void appendHeapFileRecord(final IFileStorable heapRecord)
+ throws HeapException {
+ assertTransactionOpenned();
+ cache.put(heapRecord.getPositionInFile(), heapRecord);
+ }
+
+ @Override
+ public void clear() throws HeapException {
+ assertTransactionOpenned();
+ cache.clear();
+ fileForStorable.deleteFileIfExists();
+ }
+
+ @Override
+ public void delete(final long positionInFile) throws HeapException {
+ assertTransactionOpenned();
+ cache.remove(positionInFile);
+ }
+
+ @Override
+ public boolean isCrashSafeMode() {
+ return false;
+ }
+
+ @Override
+ public boolean wasBadFileStableState() throws HeapException {
+ return false;
+ }
+
+ @Override
+ public boolean isDataLost() {
+ return false;
+ }
+
+ @Override
+ public String backup(long identifier, int maxBackup) throws HeapException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getNumberOfHeaprecordInMemory() {
+ return cache.size() + 1;
+ }
+
+ private void assertTransactionOpenned() throws HeapException {
+ if (!transactionOpen) {
+ throw new HeapException("transaction closed");
+ }
+ }
+
+ private void assertTransactionClosed() throws HeapException {
+ if (transactionOpen) {
+ throw new HeapException("transaction openned");
+ }
+ }
+}
Modified: trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/BtreePlusEntityTests.java
===================================================================
--- trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/BtreePlusEntityTests.java 2012-04-26 02:39:10 UTC (rev 3032)
+++ trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/BtreePlusEntityTests.java 2012-04-26 03:53:20 UTC (rev 3033)
@@ -44,6 +44,7 @@
// $JUnit-BEGIN$
suite.addTestSuite(LeafPageTest.class);
suite.addTestSuite(NonTerminalPageTest.class);
+ suite.addTestSuite(DataBlockPageTest.class);
// $JUnit-END$
return suite;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-26 03:53:27
|
Revision: 3033
http://joafip.svn.sourceforge.net/joafip/?rev=3033&view=rev
Author: luc_peuvrier
Date: 2012-04-26 03:53:20 +0000 (Thu, 26 Apr 2012)
Log Message:
-----------
added mock for IheapElementManager and IFileStorable
and some corrections
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractPageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/EnumRecordType.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/FreePage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/HeaderPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageConstant.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/PageRecord.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecordable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapElementManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/IHeapRecordFactory.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/TestHeapElementManager.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/BtreePlusEntityTests.java
Added Paths:
-----------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockFileForStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/mock/MockHeapElementManager.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-26 02:39:17
|
Revision: 3032
http://joafip.svn.sourceforge.net/joafip/?rev=3032&view=rev
Author: luc_peuvrier
Date: 2012-04-26 02:39:10 +0000 (Thu, 26 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. DataBlockPage and DataBlock tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/DataBlockPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java 2012-04-25 08:29:40 UTC (rev 3031)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java 2012-04-26 02:39:10 UTC (rev 3032)
@@ -35,7 +35,7 @@
private IPageRecord pageRecord;
- public void setPageRecord(IPageRecord pageRecord) {
+ public void setPageRecord(final IPageRecord pageRecord) {
this.pageRecord = pageRecord;
}
@@ -46,15 +46,21 @@
@Override
public void setValueIsChangedValueToSave() throws HeapException {
- pageRecord.setValueIsChangedValueToSave();
+ if (pageRecord != null) {
+ pageRecord.setValueIsChangedValueToSave();
+ }
}
@Override
public void setValueIsNotChanged() {
- pageRecord.setValueIsNotChanged();
+ if (pageRecord != null) {
+ pageRecord.setValueIsNotChanged();
+ }
}
public long getPositionInFile() {
+ // ASSERTX
+ assert pageRecord != null;
return pageRecord.getPositionInFile();
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java 2012-04-25 08:29:40 UTC (rev 3031)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java 2012-04-26 02:39:10 UTC (rev 3032)
@@ -136,13 +136,13 @@
/**/((((long) data[4]) & 0xff) << 24) |
/**/((((long) data[5]) & 0xff) << 16) |
/**/((((long) data[6]) & 0xff) << 8) |
- /**/(((long) data[0]) & 0xff);
+ /**/(((long) data[7]) & 0xff);
}
@Override
- public long getPosition() {
+ public long getPositionInFile() {
if (position == -1) {
- position = dataBlockPage.position(indexInDataBlockPage);
+ position = dataBlockPage.getPositionInFile(indexInDataBlockPage);
}
return position;
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java 2012-04-25 08:29:40 UTC (rev 3031)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java 2012-04-26 02:39:10 UTC (rev 3032)
@@ -32,10 +32,9 @@
*/
public class DataBlockPage extends AbstractElement {
- private static final int FIX_VALUE_SIZE =
+ public static final int HEAD_SIZE =
/**/1/* byte size for record type */+
- /**/1/* byte size for bits */+
- /**/4/* int size for crc32 */;
+ /**/1/* byte size for bits */;
private byte bits;
@@ -45,33 +44,41 @@
private final IDataBlock[] dataBlocks;
+ private final int numberOfBlock;
+
+ public static byte bitsForLength(int length) throws HeapException {
+ for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits <= PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
+ if (length < (1 << bits)) {
+ return bits;
+ }
+ }
+ throw new HeapException("length " + length + " to big for "
+ + PageConstant.MAX_DATA_BLOCK_BITS + " bits storage");
+ }
+
public DataBlockPage(final byte bits) {
super();
this.bits = bits;
dataBlockDataSize = 1 << bits;
- // the less numberOfPageValue which for
- // numberOfPage * PAGE_SIZE >= FIX_VALUE_SIZE + numberOfBlock *
- // dataBlockDataSize
- // numberOfBlock=1 if dataBlockDataSize > PAGE_SIZE - FIX_VALUE_SIZE
- //
- final int numberOfBlock;
- if (dataBlockDataSize > PageConstant.PAGE_SIZE - FIX_VALUE_SIZE) {
+ if (dataBlockDataSize > PageConstant.PAGE_SIZE - HEAD_SIZE - 4/* crc32 */) {
// one data block on one or more pages
numberOfBlock = 1;
- final int totalSize = FIX_VALUE_SIZE
- + /* numberOfBlock* */dataBlockDataSize;
+ final int totalSize = HEAD_SIZE + dataBlockDataSize + 4/* crc32 */;
final int n = totalSize >> PageConstant.PAGE_BITS;
if ((totalSize & PageConstant.IN_PAGE_POSITION_MASK) == 0) {
numberOfPage = n;
} else {
numberOfPage = n + 1;
}
+ // FIXMELUC ____________waste space, see below
+ // dataBlockDataSize=(numberOfPage<<PageConstant.PAGE_BITS)-
+ // HEAD_SIZE - 4/* crc32 */
} else {
// more than one block in one page
numberOfPage = 1;
// numberOfBlock = ((int)PageConstant.PAGE_SIZE - FIX_VALUE_SIZE)
// / dataBlockDataSize;
- numberOfBlock = ((int) PageConstant.PAGE_SIZE - FIX_VALUE_SIZE) >> bits;
+ numberOfBlock = ((int) PageConstant.PAGE_SIZE - HEAD_SIZE - 4/* crc32 */) >> bits;
}
final int minSize = bits == PageConstant.MIN_DATA_BLOCK_BITS ? 0
: ((1 << (bits - 1)) + 1);
@@ -105,30 +112,36 @@
@Override
public int getByteSize() {
return numberOfPage * (int) PageConstant.PAGE_SIZE;
+ // FIXMELUC _____________use <<
+ // return numberOfPage <<PageConstant.PAGE_BITS
}
+ public int getNumberOfBlock() {
+ return numberOfBlock;
+ }
+
public IDataBlock[] getDataBlocks() {
return dataBlocks;
}
public IDataBlock getDataBlock(final long dataBlockPosition) {
// >> bits as divide by data block size
- final int index = ((int) (dataBlockPosition - getPositionInFile()) - FIX_VALUE_SIZE) >> bits;
+ final int index = ((int) (dataBlockPosition - getPositionInFile()) - HEAD_SIZE) >> bits;
return dataBlocks[index];
}
- public long position(final int index) {
- return getPositionInFile() + FIX_VALUE_SIZE + (index << bits);
+ public long getPositionInFile(final int index) {
+ return getPositionInFile() + HEAD_SIZE + (index << bits);
}
public void setAllFree() throws HeapException {
- long nextPosition = getPositionInFile() + FIX_VALUE_SIZE
- + dataBlockDataSize;
+ long nextPosition = getPositionInFile() + HEAD_SIZE + dataBlockDataSize;
for (int index = 0; index < dataBlocks.length - 1; index++) {
dataBlocks[index].setNextFreeDataBlockPosition(nextPosition);
nextPosition += dataBlockDataSize;
}
dataBlocks[dataBlocks.length - 1].setNextFreeDataBlockPosition(-1L);
+ setValueIsChangedValueToSave();
}
@Override
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java 2012-04-25 08:29:40 UTC (rev 3031)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java 2012-04-26 02:39:10 UTC (rev 3032)
@@ -32,7 +32,7 @@
*/
public interface IDataBlock extends IStateStored {
- long getPosition();
+ long getPositionInFile();
void setData(byte[] data) throws HeapException;
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java 2012-04-25 08:29:40 UTC (rev 3031)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java 2012-04-26 02:39:10 UTC (rev 3032)
@@ -114,15 +114,17 @@
return next;
}
- public void setNext(final long next) {
+ public void setNext(final long next) throws HeapException {
this.next = next;
+ setValueIsChangedValueToSave();
}
public void setEntry(final int index, final long pagePointer,
- final DataRecordIdentifier key) {
+ final DataRecordIdentifier key) throws HeapException {
dataBlockPosition[index] = pagePointer;
keys[index] = key;
byteSize = 0;// unknown size because key size change
+ setValueIsChangedValueToSave();
}
@Override
@@ -169,7 +171,8 @@
public void setDataBlock(final int index, final IDataBlock dataBlock)
throws HeapException {
- dataBlockPosition[index] = dataBlock.getPosition();
+ dataBlockPosition[index] = dataBlock.getPositionInFile();
+ setValueIsChangedValueToSave();
}
/**
@@ -197,7 +200,8 @@
insertBeforeIndex);
System.arraycopy(keys, 0, newKeys, 0, insertBeforeIndex);
}
- newDataBlockPosition[insertBeforeIndex] = dataBlock.getPosition();
+ newDataBlockPosition[insertBeforeIndex] = dataBlock
+ .getPositionInFile();
newKeys[insertBeforeIndex] = dataRecordIdentifier;
if (afterLength != 0) {
System.arraycopy(dataBlockPosition, insertBeforeIndex,
@@ -212,6 +216,7 @@
// ASSERTX
assert byteSize == computeByteSize() : byteSize + " for "
+ computeByteSize() + " computed";
+ setValueIsChangedValueToSave();
}
return canAdd;
}
@@ -235,6 +240,7 @@
final LeafPage newLeafPage = new LeafPage(
newLeafPageNumberOfKeyEntries, newLeafPageDataBlockPosition,
newLeafPageKeys);
+ newLeafPage.setParentPage(getParentPage(), getInParentIndex() + 1);
dataBlockPosition = newDataBlockPosition;
keys = newKeys;
numberOfKeyEntries = newNumberOfKeyEntries;
@@ -248,6 +254,7 @@
throw new HeapException("failed add in splitted leaf page");
}
}
+ setValueIsChangedValueToSave();
return newLeafPage;
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-25 08:29:40 UTC (rev 3031)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-26 02:39:10 UTC (rev 3032)
@@ -100,11 +100,12 @@
}
public void setEntry(final int index, final long pagePointer,
- final DataRecordIdentifier key) {
+ final DataRecordIdentifier key) throws HeapException {
pagePositions[index] = pagePointer;
if (key != null) {
keys[index] = key;
}
+ setValueIsChangedValueToSave();
}
@Override
@@ -197,6 +198,7 @@
byteSize += entrySize;
// ASSERTX
assert byteSize == computeByteSize();
+ setValueIsChangedValueToSave();
return byteSize < PageConstant.PAGE_SIZE;
}
@@ -238,10 +240,11 @@
byteSize += entrySize;
// ASSERTX
assert byteSize == computeByteSize();
+ setValueIsChangedValueToSave();
return byteSize < PageConstant.PAGE_SIZE;
}
- public INonTerminalPage split() {
+ public INonTerminalPage split() throws HeapException {
final int splitIndex = numberOfKeyEntries / 2;
middleKey = keys[splitIndex];
final int newNumberOfKeyEntries = splitIndex;
@@ -262,6 +265,7 @@
pagePositions = newPagePosition;
numberOfKeyEntries = newNumberOfKeyEntries;
updateByteSize();
+ setValueIsChangedValueToSave();
return nonTerminalPage;
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-25 08:29:40 UTC (rev 3031)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-26 02:39:10 UTC (rev 3032)
@@ -255,6 +255,7 @@
LeafPage newLeafPage = leafPage.split(dataRecordIdentifier,
dataBlock);
btreePlusElementMgr.appendPageRecordable(newLeafPage);
+ newLeafPage.setValueIsChangedValueToSave();
leafPage.setNext(newLeafPage.getPositionInFile());
NonTerminalPage nonTerminalPage = (NonTerminalPage) leafPage
@@ -269,6 +270,8 @@
do {
btreePlusElementMgr
.appendPageRecordable(newNonTerminalPage);
+ newNonTerminalPage
+ .setValueIsChangedValueToSave();
DataRecordIdentifier middleKey = nonTerminalPage
.getAndClearMiddleKey();
NonTerminalPage parent = (NonTerminalPage) nonTerminalPage
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-25 08:29:40 UTC (rev 3031)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-26 02:39:10 UTC (rev 3032)
@@ -262,7 +262,7 @@
}
public IDataBlock createDataBlock(final byte[] data) throws HeapException {
- final byte bits = bitsForLength(data.length);
+ final byte bits = DataBlockPage.bitsForLength(data.length);
final long freeDataBlockPosition = header
.getFreeDataBlockPosition(bits);
final IDataBlock dataBlock;
@@ -286,20 +286,10 @@
final long freeDataBlockPosition = header
.getFreeDataBlockPosition(bits);
dataBlock.setNextFreeDataBlockPosition(freeDataBlockPosition);
- final long position = dataBlock.getPosition();
+ final long position = dataBlock.getPositionInFile();
header.setFreeDataBlockPosition(bits, position);
}
- private byte bitsForLength(final int length) throws HeapException {
- for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits <= PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
- if (length < (1 << bits)) {
- return bits;
- }
- }
- throw new HeapException("length " + length + " to big for "
- + PageConstant.MAX_DATA_BLOCK_BITS + " bits storage");
- }
-
public void appendPageRecordable(IPageRecordable pageRecordable)
throws HeapException {
long pageNumber = header.getFileSizeAsNumberOfPage() + 1;
Added: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/DataBlockPageTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/DataBlockPageTest.java (rev 0)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/DataBlockPageTest.java 2012-04-26 02:39:10 UTC (rev 3032)
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.AbstractJoafipCommonTestCase;
+import net.sf.joafip.NoStorableAccess;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestException;
+import net.sf.joafip.btreeplus.entity.mock.MockPageRecord;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+@NoStorableAccess
+public class DataBlockPageTest extends AbstractJoafipCommonTestCase {
+
+ public DataBlockPageTest() throws TestException {
+ super();
+ }
+
+ public DataBlockPageTest(final String name) throws TestException {
+ super(name);
+ }
+
+ public void testCreation() throws HeapException {
+ for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
+ checkCreationState(bits);
+ }
+ }
+
+ private void checkCreationState(final byte bits) throws HeapException {
+ final DataBlockPage dataBlockPage = new DataBlockPage(bits);
+ final MockPageRecord pageRecord = new MockPageRecord();
+ pageRecord.setPositionInFile(1545);
+ dataBlockPage.setPageRecord(pageRecord);
+
+ final int numberOfBlock = dataBlockPage.getNumberOfBlock();
+ final int blockByteSize = 1 << bits;
+ final long dataAreaSize = PageConstant.PAGE_SIZE
+ - DataBlockPage.HEAD_SIZE;
+ final int numberOfPage = (int) ((blockByteSize <= dataAreaSize) ? 1
+ : ((blockByteSize + DataBlockPage.HEAD_SIZE)
+ / PageConstant.PAGE_SIZE + (((blockByteSize + DataBlockPage.HEAD_SIZE)
+ % PageConstant.PAGE_SIZE == 0) ? 0 : 1)));
+
+ final int dataBlockPageByteSize = (int) (numberOfPage * PageConstant.PAGE_SIZE);
+
+ assertEquals("bad record type", EnumRecordType.DATA_BLOCK,
+ dataBlockPage.getRecordType());
+ assertEquals("bad number of bits", bits, dataBlockPage.getBits());
+ assertEquals("bad position in file", 1545,
+ dataBlockPage.getPositionInFile());
+ assertEquals("bad number of page (bits" + bits + ")", numberOfPage,
+ dataBlockPage.getNumberOfPage());
+ assertEquals("bad byte size", dataBlockPageByteSize,
+ dataBlockPage.getByteSize());
+ dataBlockPage.setAllFree();
+ IDataBlock[] dataBlocks = dataBlockPage.getDataBlocks();
+ assertEquals("number of block missmatch", numberOfBlock,
+ dataBlocks.length);
+ int index = 0;
+ long expectedCurrentPositionInFile = dataBlockPage.getPositionInFile()
+ + DataBlockPage.HEAD_SIZE;
+ long nextFreeDataBlockPosition = dataBlockPage.getPositionInFile()
+ + DataBlockPage.HEAD_SIZE;
+ for (IDataBlock dataBlock : dataBlocks) {
+ assertEquals("bad number of bits", bits, dataBlock.getBits());
+ final long positionInFile = dataBlock.getPositionInFile();
+ assertEquals("bad position in file", expectedCurrentPositionInFile,
+ positionInFile);
+ assertSame("bad block in block page", dataBlock,
+ dataBlockPage.getDataBlock(positionInFile));
+ assertEquals("data block #" + index + " (bits " + bits
+ + ") bad free link", positionInFile,
+ nextFreeDataBlockPosition);
+ nextFreeDataBlockPosition = dataBlock
+ .getNextFreeDataBlockPosition();
+ index++;
+ expectedCurrentPositionInFile += blockByteSize;
+ }
+ assertEquals("data block #" + index + " (bits " + bits
+ + ") bad free link", -1L, nextFreeDataBlockPosition);
+ }
+}
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java 2012-04-25 08:29:40 UTC (rev 3031)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java 2012-04-26 02:39:10 UTC (rev 3032)
@@ -24,9 +24,11 @@
package net.sf.joafip.btreeplus.entity;
import net.sf.joafip.AbstractJoafipCommonTestCase;
+import net.sf.joafip.NoStorableAccess;
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.TestException;
import net.sf.joafip.btreeplus.entity.mock.MockDataBlock;
+import net.sf.joafip.btreeplus.entity.mock.MockPageRecord;
import net.sf.joafip.btreeplus.entity.mock.MockPageRecordable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
@@ -37,8 +39,11 @@
*
*/
@NotStorableClass
+@NoStorableAccess
public class LeafPageTest extends AbstractJoafipCommonTestCase {
+ private final static IPageRecord PAGE_RECORD = new MockPageRecord();
+
public LeafPageTest() throws TestException {
super();
}
@@ -49,6 +54,7 @@
public void testCreation() {
LeafPage leafPage = new LeafPage();
+ leafPage.setPageRecord(PAGE_RECORD);
assertEquals("must be empty", 0, leafPage.getNumberOfKeyEntries());
assertEquals("must be one page", 1, leafPage.getNumberOfPage());
assertEquals("bad record type", EnumRecordType.LEAF_PAGE,
@@ -58,6 +64,7 @@
public void testAdd() throws HeapException {
LeafPage leafPage = new LeafPage();
+ leafPage.setPageRecord(PAGE_RECORD);
addToLeafPage(leafPage, 1000/* position */, 10/* key value */, 10, 1);
addToLeafPage(leafPage, 2000/* position */, 5/* key value */, 10, 2);
addToLeafPage(leafPage, 3000/* position */, 15/* key value */, 15, 3);
@@ -101,7 +108,7 @@
numberOfKeyEntries, leafPage.getNumberOfKeyEntries());
assertEquals("bad byte size", byteSize(numberOfKeyEntries),
leafPage.getByteSize());
- assertEquals("must find", dataBlock.getPosition(),
+ assertEquals("must find", dataBlock.getPositionInFile(),
leafPage.getDataBlockPosition(dataRecordIdentifier));
assertEquals("must not find", -1L,
leafPage.getDataBlockPosition(new DataRecordIdentifier(0)));
@@ -111,6 +118,7 @@
public void testSetDataBlock() throws HeapException {
final LeafPage leafPage = new LeafPage(1);
+ leafPage.setPageRecord(PAGE_RECORD);
final MockDataBlock dataBlock = new MockDataBlock();
final long position = 1000;
dataBlock.setPosition(position);
@@ -120,8 +128,9 @@
leafPage.getBlockPointer(index));
}
- public void testSetEntry() {
+ public void testSetEntry() throws HeapException {
final LeafPage leafPage = new LeafPage(1);
+ leafPage.setPageRecord(PAGE_RECORD);
final int index = 0;
final long pagePointer = 2000;
final int keyValue = 10;
@@ -135,7 +144,8 @@
public void testSetParentPage() throws HeapException {
final LeafPage leafPage = new LeafPage();
- IPageRecordable parentPage = new MockPageRecordable();
+ leafPage.setPageRecord(PAGE_RECORD);
+ final IPageRecordable parentPage = new MockPageRecordable();
final int inParentIndex = 5;
leafPage.setParentPage(parentPage, inParentIndex);
assertEquals("bad parent page", parentPage, leafPage.getParentPage());
@@ -143,8 +153,9 @@
leafPage.getInParentIndex());
}
- public void testSetNext() {
+ public void testSetNext() throws HeapException {
final LeafPage leafPage = new LeafPage();
+ leafPage.setPageRecord(PAGE_RECORD);
final long next = 5000;
leafPage.setNext(next);
assertEquals("bad next value", next, leafPage.getNext());
@@ -152,6 +163,7 @@
public void testSplit1() throws HeapException {
final LeafPage leafPage = new LeafPage();
+ leafPage.setPageRecord(PAGE_RECORD);
final int maxNumberOfEntries = maxNumberOfEntries();
int count = 0;
while (leafPage.getNumberOfKeyEntries() != maxNumberOfEntries) {
@@ -170,6 +182,7 @@
public void testSplit2() throws HeapException {
final LeafPage leafPage = new LeafPage();
+ leafPage.setPageRecord(PAGE_RECORD);
final int maxNumberOfEntries = maxNumberOfEntries();
int count = 1;
while (leafPage.getNumberOfKeyEntries() != maxNumberOfEntries) {
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java 2012-04-25 08:29:40 UTC (rev 3031)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java 2012-04-26 02:39:10 UTC (rev 3032)
@@ -24,11 +24,12 @@
package net.sf.joafip.btreeplus.entity;
import net.sf.joafip.AbstractJoafipCommonTestCase;
+import net.sf.joafip.NoStorableAccess;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.StorableAccess;
import net.sf.joafip.TestException;
import net.sf.joafip.btreeplus.entity.mock.MockLeafPage;
import net.sf.joafip.btreeplus.entity.mock.MockNonTerminalPage;
+import net.sf.joafip.btreeplus.entity.mock.MockPageRecord;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
@@ -38,9 +39,11 @@
*
*/
@NotStorableClass
-@StorableAccess
+@NoStorableAccess
public class NonTerminalPageTest extends AbstractJoafipCommonTestCase {
+ private final static IPageRecord PAGE_RECORD = new MockPageRecord();
+
public NonTerminalPageTest() throws TestException {
super();
}
@@ -63,10 +66,11 @@
public void testAddLeafPage() throws HeapException {
// A 10 B
final NonTerminalPage nonTerminalPage = new NonTerminalPage(1);
- final MockLeafPage leafPageA = new MockLeafPage();
+ nonTerminalPage.setPageRecord(PAGE_RECORD);
+ final MockLeafPage leafPageA = newMockLeafPage();
final long pageAPositionInFile = 1000;
leafPageA.setPositionInFile(pageAPositionInFile);
- final MockLeafPage leafPageB = new MockLeafPage();
+ final MockLeafPage leafPageB = newMockLeafPage();
final long pageBPositionInFile = 2000;
leafPageB.setPositionInFile(pageBPositionInFile);
final DataRecordIdentifier key10 = new DataRecordIdentifier(10);
@@ -82,7 +86,7 @@
nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
// A 10 B -> A 5 C 10 B
- final MockLeafPage leafPageC = new MockLeafPage();
+ final MockLeafPage leafPageC = newMockLeafPage();
final long pageCPositionInFile = 3000;
leafPageC.setPositionInFile(pageCPositionInFile);
final DataRecordIdentifier key5 = new DataRecordIdentifier(5);
@@ -101,7 +105,7 @@
nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
// A 5 C 10 B -> A 5 C 10 B 15 D
- final MockLeafPage leafPageD = new MockLeafPage();
+ final MockLeafPage leafPageD = newMockLeafPage();
final long pageDPositionInFile = 4000;
leafPageD.setPositionInFile(pageDPositionInFile);
final DataRecordIdentifier key15 = new DataRecordIdentifier(15);
@@ -121,7 +125,7 @@
nonTerminalPage.getIndex(new DataRecordIdentifier(16)));
// A 5 C 10 B 15 D -> A 5 C 7 E 10 B 15 D
- final MockLeafPage leafPageE = new MockLeafPage();
+ final MockLeafPage leafPageE = newMockLeafPage();
final long pageEPositionInFile = 5000;
leafPageE.setPositionInFile(pageEPositionInFile);
final DataRecordIdentifier key7 = new DataRecordIdentifier(7);
@@ -144,7 +148,7 @@
nonTerminalPage.getIndex(new DataRecordIdentifier(16)));
// A 5 C 7 E 10 B 15 D -> A 5 C 7 E 10 B 15 D 17 F
- final MockLeafPage leafPageF = new MockLeafPage();
+ final MockLeafPage leafPageF = newMockLeafPage();
final long pageFPositionInFile = 6000;
leafPageF.setPositionInFile(pageFPositionInFile);
final DataRecordIdentifier key17 = new DataRecordIdentifier(17);
@@ -172,10 +176,11 @@
public void testAddLeafPageNeedSplit() throws HeapException {
// A 10 B
final NonTerminalPage nonTerminalPage = new NonTerminalPage(1);
- final MockLeafPage leafPageA = new MockLeafPage();
+ nonTerminalPage.setPageRecord(PAGE_RECORD);
+ final MockLeafPage leafPageA = newMockLeafPage();
final long pageAPositionInFile = 1000;
leafPageA.setPositionInFile(pageAPositionInFile);
- final MockLeafPage leafPageB = new MockLeafPage();
+ final MockLeafPage leafPageB = newMockLeafPage();
final long pageBPositionInFile = 2000;
leafPageB.setPositionInFile(pageBPositionInFile);
final DataRecordIdentifier key10 = new DataRecordIdentifier(10);
@@ -186,14 +191,14 @@
MockLeafPage leftPage = leafPageB;
final int maxNumberOfEntries = maxNumberOfEntries();
while (nonTerminalPage.getNumberOfKeyEntries() < maxNumberOfEntries) {
- final MockLeafPage rightPage = new MockLeafPage();
+ final MockLeafPage rightPage = newMockLeafPage();
leftPage.setInParentIndex(nonTerminalPage.getNumberOfKeyEntries() - 1);
leftPage.setLastKey(key10);
assertTrue("must not need split",
nonTerminalPage.add(leftPage, rightPage));
leftPage = rightPage;
}
- final MockLeafPage rightPage = new MockLeafPage();
+ final MockLeafPage rightPage = newMockLeafPage();
leftPage.setInParentIndex(nonTerminalPage.getNumberOfKeyEntries() - 1);
leftPage.setLastKey(key10);
assertFalse("must need split", nonTerminalPage.add(leftPage, rightPage));
@@ -202,10 +207,11 @@
public void testAddNonTerminalPage() throws HeapException {
// A 10 B
final NonTerminalPage nonTerminalPage = new NonTerminalPage(1);
- final MockNonTerminalPage pageA = new MockNonTerminalPage();
+ nonTerminalPage.setPageRecord(PAGE_RECORD);
+ final MockNonTerminalPage pageA = newMockNonTerminalPage();
final long pageAPositionInFile = 1000;
pageA.setPositionInFile(pageAPositionInFile);
- final MockNonTerminalPage pageB = new MockNonTerminalPage();
+ final MockNonTerminalPage pageB = newMockNonTerminalPage();
final long pageBPositionInFile = 2000;
pageB.setPositionInFile(pageBPositionInFile);
final DataRecordIdentifier key10 = new DataRecordIdentifier(10);
@@ -221,7 +227,7 @@
nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
// A 10 B -> A 5 C 10 B
- final MockNonTerminalPage pageC = new MockNonTerminalPage();
+ final MockNonTerminalPage pageC = newMockNonTerminalPage();
final long pageCPositionInFile = 3000;
pageC.setPositionInFile(pageCPositionInFile);
final DataRecordIdentifier key5 = new DataRecordIdentifier(5);
@@ -239,7 +245,7 @@
// ------------
// A 5 C 10 B -> A 5 C 10 B 15 D
- final MockNonTerminalPage pageD = new MockNonTerminalPage();
+ final MockNonTerminalPage pageD = newMockNonTerminalPage();
final long pageDPositionInFile = 4000;
pageD.setPositionInFile(pageDPositionInFile);
final DataRecordIdentifier key15 = new DataRecordIdentifier(15);
@@ -258,7 +264,7 @@
nonTerminalPage.getIndex(new DataRecordIdentifier(16)));
// A 5 C 10 B 15 D -> A 5 C 7 E 10 B 15 D
- final MockNonTerminalPage pageE = new MockNonTerminalPage();
+ final MockNonTerminalPage pageE = newMockNonTerminalPage();
final long pageEPositionInFile = 5000;
pageE.setPositionInFile(pageEPositionInFile);
final DataRecordIdentifier key7 = new DataRecordIdentifier(7);
@@ -280,7 +286,7 @@
nonTerminalPage.getIndex(new DataRecordIdentifier(16)));
// A 5 C 7 E 10 B 15 D -> A 5 C 7 E 10 B 15 D 17 F
- final MockNonTerminalPage pageF = new MockNonTerminalPage();
+ final MockNonTerminalPage pageF = newMockNonTerminalPage();
final long pageFPositionInFile = 6000;
pageF.setPositionInFile(pageFPositionInFile);
final DataRecordIdentifier key17 = new DataRecordIdentifier(17);
@@ -308,10 +314,11 @@
public void testAddNonTerminalPageNeedSplit() throws HeapException {
// A 10 B
final NonTerminalPage nonTerminalPage = new NonTerminalPage(1);
- final MockNonTerminalPage pageA = new MockNonTerminalPage();
+ nonTerminalPage.setPageRecord(PAGE_RECORD);
+ final MockNonTerminalPage pageA = newMockNonTerminalPage();
final long pageAPositionInFile = 1000;
pageA.setPositionInFile(pageAPositionInFile);
- final MockNonTerminalPage pageB = new MockNonTerminalPage();
+ final MockNonTerminalPage pageB = newMockNonTerminalPage();
final long pageBPositionInFile = 2000;
pageB.setPositionInFile(pageBPositionInFile);
final DataRecordIdentifier key10 = new DataRecordIdentifier(10);
@@ -322,22 +329,23 @@
MockNonTerminalPage leftPage = pageB;
final int maxNumberOfEntries = maxNumberOfEntries();
while (nonTerminalPage.getNumberOfKeyEntries() < maxNumberOfEntries) {
- final MockNonTerminalPage rightPage = new MockNonTerminalPage();
+ final MockNonTerminalPage rightPage = newMockNonTerminalPage();
leftPage.setInParentIndex(nonTerminalPage.getNumberOfKeyEntries() - 1);
assertTrue("must not need split",
nonTerminalPage.add(leftPage, key10, rightPage));
leftPage = rightPage;
}
- final MockNonTerminalPage rightPage = new MockNonTerminalPage();
+ final MockNonTerminalPage rightPage = newMockNonTerminalPage();
leftPage.setInParentIndex(nonTerminalPage.getNumberOfKeyEntries() - 1);
assertFalse("must need split",
nonTerminalPage.add(leftPage, key10, rightPage));
}
- public void testSplit() {
+ public void testSplit() throws HeapException {
final int maxNumberOfEntries = maxNumberOfEntries() + 1;
final NonTerminalPage nonTerminalPage = new NonTerminalPage(
maxNumberOfEntries);
+ nonTerminalPage.setPageRecord(PAGE_RECORD);
for (int index = 0; index < maxNumberOfEntries; index++) {
nonTerminalPage.setEntry(index, index * 1000,
new DataRecordIdentifier(index));
@@ -413,6 +421,18 @@
nonTerminalPage.getPagePointer(numberOfEntries));
}
+ private MockLeafPage newMockLeafPage() throws HeapException {
+ final MockLeafPage mockLeafPage = new MockLeafPage();
+ mockLeafPage.setPageRecord(PAGE_RECORD);
+ return mockLeafPage;
+ }
+
+ private MockNonTerminalPage newMockNonTerminalPage() throws HeapException {
+ final MockNonTerminalPage mockNonTerminalPage = new MockNonTerminalPage();
+ mockNonTerminalPage.setPageRecord(PAGE_RECORD);
+ return mockNonTerminalPage;
+ }
+
private int byteSize(final int numberOfKeyEntries) {
int xbyteSize = 1/* byte size for record type */+
/**/4/* int size for number of entries */+
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java 2012-04-25 08:29:40 UTC (rev 3031)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java 2012-04-26 02:39:10 UTC (rev 3032)
@@ -48,7 +48,7 @@
}
@Override
- public long getPosition() {
+ public long getPositionInFile() {
return position;
}
Added: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java (rev 0)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java 2012-04-26 02:39:10 UTC (rev 3032)
@@ -0,0 +1,59 @@
+package net.sf.joafip.btreeplus.entity.mock;
+
+import net.sf.joafip.btreeplus.entity.IPageRecord;
+import net.sf.joafip.kvstore.service.HeapException;
+
+public class MockPageRecord implements IPageRecord {
+
+ private long positionInFile;
+
+ @Override
+ public long getPreviousRecordPositionInFile() throws HeapException {
+ return 0;
+ }
+
+ @Override
+ public byte[] writeToFile() throws HeapException {
+ return null;
+ }
+
+ @Override
+ public void readFromFile() throws HeapException {
+ }
+
+ @Override
+ public void clear() {
+ }
+
+ @Override
+ public boolean isJustCreated() {
+ return false;
+ }
+
+ @Override
+ public int getRecordSize() throws HeapException {
+ return 0;
+ }
+
+ public void setPositionInFile(final long positionInFile) {
+ this.positionInFile = positionInFile;
+ }
+
+ @Override
+ public long getPositionInFile() {
+ return positionInFile;
+ }
+
+ @Override
+ public void setValueIsChangedValueToSave() throws HeapException {
+ }
+
+ @Override
+ public void setValueIsNotChanged() {
+ }
+
+ @Override
+ public boolean isValueChangedToSave() {
+ return false;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-26 02:39:16
|
Revision: 3032
http://joafip.svn.sourceforge.net/joafip/?rev=3032&view=rev
Author: luc_peuvrier
Date: 2012-04-26 02:39:10 +0000 (Thu, 26 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. DataBlockPage and DataBlock tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/AbstractElement.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/DataBlockPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/IDataBlock.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/DataBlockPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecord.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-25 08:29:49
|
Revision: 3031
http://joafip.svn.sourceforge.net/joafip/?rev=3031&view=rev
Author: luc_peuvrier
Date: 2012-04-25 08:29:40 +0000 (Wed, 25 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. NonTerminalPage tests ok. split test was missing
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/INonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecordable.java
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/INonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/INonTerminalPage.java 2012-04-25 04:28:28 UTC (rev 3030)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/INonTerminalPage.java 2012-04-25 08:29:40 UTC (rev 3031)
@@ -23,6 +23,7 @@
*/
package net.sf.joafip.btreeplus.entity;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
/**
@@ -37,4 +38,10 @@
long getPositionInFile();
+ int getNumberOfKeyEntries();
+
+ long getPagePointer(int index);
+
+ DataRecordIdentifier getKey(int index);
+
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-25 04:28:28 UTC (rev 3030)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-25 08:29:40 UTC (rev 3031)
@@ -131,14 +131,17 @@
return xbyteSize;
}
+ @Override
public int getNumberOfKeyEntries() {
return numberOfKeyEntries;
}
+ @Override
public long getPagePointer(final int index) {
return pagePositions[index];
}
+ @Override
public DataRecordIdentifier getKey(final int index) {
return keys[index];
}
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java 2012-04-25 04:28:28 UTC (rev 3030)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java 2012-04-25 08:29:40 UTC (rev 3031)
@@ -335,15 +335,62 @@
}
public void testSplit() {
+ final int maxNumberOfEntries = maxNumberOfEntries() + 1;
+ final NonTerminalPage nonTerminalPage = new NonTerminalPage(
+ maxNumberOfEntries);
+ for (int index = 0; index < maxNumberOfEntries; index++) {
+ nonTerminalPage.setEntry(index, index * 1000,
+ new DataRecordIdentifier(index));
+ }
+ nonTerminalPage.setEntry(maxNumberOfEntries, maxNumberOfEntries * 1000,
+ null);
+ nonTerminalPage.updateByteSize();
- }
+ final int splitIndex = maxNumberOfEntries / 2;
+ final int leftNumberOfEntries = splitIndex;
+ final int rightNumberOfEntries = maxNumberOfEntries
+ - leftNumberOfEntries - 1;
+ final INonTerminalPage rightPage = nonTerminalPage.split();
- public void testSetEntry() {
+ final DataRecordIdentifier middleKey = nonTerminalPage
+ .getAndClearMiddleKey();
+ assertEquals("", leftNumberOfEntries,
+ nonTerminalPage.getNumberOfKeyEntries());
+ assertEquals("", rightNumberOfEntries,
+ rightPage.getNumberOfKeyEntries());
+
+ for (int count = 0; count < leftNumberOfEntries; count++) {
+ assertEquals("bad page pointer for #" + count, count * 1000,
+ nonTerminalPage.getPagePointer(count));
+ assertEquals("bad key #" + count, new DataRecordIdentifier(count),
+ nonTerminalPage.getKey(count));
+ }
+ assertEquals("bad page pointer for #" + leftNumberOfEntries,
+ leftNumberOfEntries * 1000,
+ nonTerminalPage.getPagePointer(leftNumberOfEntries));
+ assertEquals("bad middle key", new DataRecordIdentifier(splitIndex),
+ middleKey);
+ int index = splitIndex + 1;
+ for (int count = 0; count < rightNumberOfEntries; count++) {
+ assertEquals("bad page pointer for #" + count, index * 1000,
+ rightPage.getPagePointer(count));
+ assertEquals("bad key #" + count, new DataRecordIdentifier(index),
+ rightPage.getKey(count));
+ index++;
+ }
+ assertEquals("bad page pointer for #" + rightNumberOfEntries,
+ index * 1000, rightPage.getPagePointer(rightNumberOfEntries));
}
- public void testSetParentPage() {
-
+ public void testSetParentPage() throws HeapException {
+ final NonTerminalPage nonTerminalPage = new NonTerminalPage();
+ final IPageRecordable parentPage = new NonTerminalPage();
+ nonTerminalPage.setParentPage(parentPage, 10);
+ assertSame("bad parent page", parentPage,
+ nonTerminalPage.getParentPage());
+ assertEquals("bad index in parent", 10,
+ nonTerminalPage.getInParentIndex());
}
private void checkState(final NonTerminalPage nonTerminalPage,
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java 2012-04-25 04:28:28 UTC (rev 3030)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java 2012-04-25 08:29:40 UTC (rev 3031)
@@ -37,14 +37,10 @@
@Override
public void setValueIsChangedValueToSave() throws HeapException {
- // TODO Auto-generated method stub
-
}
@Override
public void setValueIsNotChanged() {
- // TODO Auto-generated method stub
-
}
public void setPosition(final long position) {
@@ -58,57 +54,45 @@
@Override
public void setData(byte[] data) throws HeapException {
- // TODO Auto-generated method stub
-
}
@Override
public byte[] getData() {
- // TODO Auto-generated method stub
return null;
}
@Override
public void setNextFreeDataBlockPosition(long nextFreeDataBlockPosition)
throws HeapException {
- // TODO Auto-generated method stub
-
}
@Override
public long getNextFreeDataBlockPosition() {
- // TODO Auto-generated method stub
return 0;
}
@Override
public byte[] getDataHolder() {
- // TODO Auto-generated method stub
return null;
}
@Override
public int getMinSize() {
- // TODO Auto-generated method stub
return 0;
}
@Override
public int getMaxSize() {
- // TODO Auto-generated method stub
return 0;
}
@Override
public byte getBits() {
- // TODO Auto-generated method stub
return 0;
}
@Override
public int getIndexInDataBlockPage() {
- // TODO Auto-generated method stub
return 0;
}
-
}
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java 2012-04-25 04:28:28 UTC (rev 3030)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java 2012-04-25 08:29:40 UTC (rev 3031)
@@ -43,50 +43,39 @@
@Override
public EnumRecordType getRecordType() {
- // TODO Auto-generated method stub
return null;
}
@Override
public int getNumberOfPage() {
- // TODO Auto-generated method stub
return 0;
}
@Override
public int getByteSize() {
- // TODO Auto-generated method stub
return 0;
}
@Override
public void updateByteSize() {
- // TODO Auto-generated method stub
-
}
@Override
public IPageRecord getPageRecord() throws HeapException {
- // TODO Auto-generated method stub
return null;
}
@Override
public void setPageRecord(IPageRecord pageRecord) throws HeapException {
- // TODO Auto-generated method stub
-
}
@Override
public void setParentPage(IPageRecordable parentPage, int inParentIndex)
throws HeapException {
- // TODO Auto-generated method stub
-
}
@Override
public IPageRecordable getParentPage() throws HeapException {
- // TODO Auto-generated method stub
return null;
}
@@ -101,14 +90,10 @@
@Override
public void setValueIsChangedValueToSave() throws HeapException {
- // TODO Auto-generated method stub
-
}
@Override
public void setValueIsNotChanged() {
- // TODO Auto-generated method stub
-
}
public void setLastKey(final DataRecordIdentifier lastKey) {
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java 2012-04-25 04:28:28 UTC (rev 3030)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java 2012-04-25 08:29:40 UTC (rev 3031)
@@ -27,6 +27,7 @@
import net.sf.joafip.btreeplus.entity.INonTerminalPage;
import net.sf.joafip.btreeplus.entity.IPageRecord;
import net.sf.joafip.btreeplus.entity.IPageRecordable;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
/**
@@ -118,4 +119,21 @@
return positionInFile;
}
+ @Override
+ public int getNumberOfKeyEntries() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public long getPagePointer(int index) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public DataRecordIdentifier getKey(int index) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecordable.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecordable.java 2012-04-25 04:28:28 UTC (rev 3030)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecordable.java 2012-04-25 08:29:40 UTC (rev 3031)
@@ -37,69 +37,52 @@
@Override
public void setValueIsChangedValueToSave() throws HeapException {
- // TODO Auto-generated method stub
-
}
@Override
public void setValueIsNotChanged() {
- // TODO Auto-generated method stub
-
}
@Override
public EnumRecordType getRecordType() {
- // TODO Auto-generated method stub
return null;
}
@Override
public int getNumberOfPage() {
- // TODO Auto-generated method stub
return 0;
}
@Override
public int getByteSize() {
- // TODO Auto-generated method stub
return 0;
}
@Override
public void updateByteSize() {
- // TODO Auto-generated method stub
-
}
@Override
public IPageRecord getPageRecord() throws HeapException {
- // TODO Auto-generated method stub
return null;
}
@Override
public void setPageRecord(IPageRecord pageRecord) throws HeapException {
- // TODO Auto-generated method stub
-
}
@Override
public void setParentPage(IPageRecordable parentPage, int inParentIndex)
throws HeapException {
- // TODO Auto-generated method stub
-
}
@Override
public IPageRecordable getParentPage() throws HeapException {
- // TODO Auto-generated method stub
return null;
}
@Override
public int getInParentIndex() throws HeapException {
- // TODO Auto-generated method stub
return 0;
}
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-25 08:29:49
|
Revision: 3031
http://joafip.svn.sourceforge.net/joafip/?rev=3031&view=rev
Author: luc_peuvrier
Date: 2012-04-25 08:29:40 +0000 (Wed, 25 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. NonTerminalPage tests ok. split test was missing
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/INonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockDataBlock.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockPageRecordable.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-25 07:14:41
|
Revision: 3030
http://joafip.svn.sourceforge.net/joafip/?rev=3030&view=rev
Author: luc_peuvrier
Date: 2012-04-25 04:28:28 +0000 (Wed, 25 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. NonTerminalPage tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/BtreePlusEntityTests.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/ILeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/INonTerminalPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-25 04:28:36
|
Revision: 3030
http://joafip.svn.sourceforge.net/joafip/?rev=3030&view=rev
Author: luc_peuvrier
Date: 2012-04-25 04:28:28 +0000 (Wed, 25 Apr 2012)
Log Message:
-----------
WIP btree plus, tests in progress. NonTerminalPage tests ok
Modified Paths:
--------------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/BtreePlusEntityTests.java
Added Paths:
-----------
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/ILeafPage.java
trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/INonTerminalPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java
trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/service/
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/ILeafPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/ILeafPage.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/ILeafPage.java 2012-04-25 04:28:28 UTC (rev 3030)
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public interface ILeafPage extends IPageRecordable {
+
+ DataRecordIdentifier getLastKey();
+
+ long getPositionInFile();
+
+}
Added: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/INonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/INonTerminalPage.java (rev 0)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/INonTerminalPage.java 2012-04-25 04:28:28 UTC (rev 3030)
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public interface INonTerminalPage extends IPageRecordable {
+
+ @Override
+ int getInParentIndex() throws HeapException;
+
+ long getPositionInFile();
+
+}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java 2012-04-24 04:44:11 UTC (rev 3029)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/LeafPage.java 2012-04-25 04:28:28 UTC (rev 3030)
@@ -33,7 +33,7 @@
* @author luc peuvrier
*
*/
-public class LeafPage extends AbstractElement {
+public class LeafPage extends AbstractElement implements ILeafPage {
private long[] dataBlockPosition;
@@ -122,6 +122,7 @@
final DataRecordIdentifier key) {
dataBlockPosition[index] = pagePointer;
keys[index] = key;
+ byteSize = 0;// unknown size because key size change
}
@Override
@@ -141,6 +142,7 @@
/**/4/* int size for number of entries */+
/**/4/* int size for crc32 */+
/**/8/* for next */;
+ // FIXMELUC ______speedup if long value key
for (int index = 0; index < numberOfKeyEntries; index++) {
xbyteSize += entrySize(keys[index]);
}
@@ -258,7 +260,7 @@
return index;
}
- public DataRecordIdentifier lastKey() {
+ public DataRecordIdentifier getLastKey() {
return keys[numberOfKeyEntries - 1];
}
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-24 04:44:11 UTC (rev 3029)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/entity/NonTerminalPage.java 2012-04-25 04:28:28 UTC (rev 3030)
@@ -33,7 +33,8 @@
* @author luc peuvrier
*
*/
-public class NonTerminalPage extends AbstractElement {
+public class NonTerminalPage extends AbstractElement implements
+ INonTerminalPage {
private long[] pagePositions;
@@ -123,6 +124,7 @@
/**/4/* int size for number of entries */+
/**/4/* int size for crc32 */+
/**/8/* last pointer long size */;
+ // FIXMELUC ______speedup if long value key
for (int index = 0; index < numberOfKeyEntries; index++) {
xbyteSize += entrySize(keys[index]);
}
@@ -149,39 +151,42 @@
public int getIndex(final DataRecordIdentifier dataRecordIdentifier) {
// FIXMELUC _______dichotomic search
int index;
- boolean found = false;
- for (index = 0; !found && index < numberOfKeyEntries; index++) {
- found = keys[index].compareTo(dataRecordIdentifier) <= 0;
+ for (index = 0; index < numberOfKeyEntries; index++) {
+ if (keys[index].compareTo(dataRecordIdentifier) >= 0) {
+ return index;
+ }
}
return index;
}
/**
*
- * @param existingLeftLeafPage
- * @param newRightLeafPage
+ * @param existingLeftILeafPage
+ * @param newRightILeafPage
* @return true if add not need split
* @throws HeapException
*/
- public boolean add(final LeafPage existingLeftLeafPage,
- final LeafPage newRightLeafPage) throws HeapException {
- final int index = existingLeftLeafPage.getInParentIndex();
- final DataRecordIdentifier key = existingLeftLeafPage.lastKey();
+ public boolean add(final ILeafPage existingLeftILeafPage,
+ final ILeafPage newRightILeafPage) throws HeapException {
+ final int index = existingLeftILeafPage.getInParentIndex();
+ final DataRecordIdentifier key = existingLeftILeafPage.getLastKey();
final int entrySize = entrySize(key);
- final int afterLength = numberOfKeyEntries - (index + 1);
+ final int afterLength = numberOfKeyEntries - index;
numberOfKeyEntries++;
DataRecordIdentifier[] newKeys = new DataRecordIdentifier[numberOfKeyEntries];
long[] newPagePosition = new long[numberOfKeyEntries + 1];
if (index != 0) {
System.arraycopy(keys, 0, newKeys, 0, index);
- System.arraycopy(pagePositions, 0, newPagePosition, 0, index);
}
+ System.arraycopy(pagePositions, 0, newPagePosition, 0, index + 1);
+
newKeys[index] = key;
- newPagePosition[index + 1] = newRightLeafPage.getPositionInFile();
- newKeys[index + 1] = newRightLeafPage.lastKey();
+ newPagePosition[index + 1] = newRightILeafPage.getPositionInFile();
System.arraycopy(pagePositions, index + 1, newPagePosition, index + 2,
- afterLength + 1);
- System.arraycopy(keys, index + 1, newKeys, index + 2, afterLength);
+ afterLength);
+ if (afterLength != 0) {
+ System.arraycopy(keys, index, newKeys, index + 1, afterLength);
+ }
keys = newKeys;
pagePositions = newPagePosition;
// ASSERTX
@@ -192,34 +197,48 @@
return byteSize < PageConstant.PAGE_SIZE;
}
- public boolean add(final NonTerminalPage leftSonNonTerminalPage,
+ /**
+ *
+ * @param leftSonNonTerminalPage
+ * @param middleKey
+ * @param rightSonNonTerminalPage
+ * @return true if add not need split
+ * @throws HeapException
+ */
+ public boolean add(final INonTerminalPage leftSonNonTerminalPage,
final DataRecordIdentifier middleKey,
- final NonTerminalPage rightSonNonTerminalPage) throws HeapException {
+ final INonTerminalPage rightSonNonTerminalPage)
+ throws HeapException {
final int index = leftSonNonTerminalPage.getInParentIndex();
final int entrySize = entrySize(middleKey);
- final int afterLength = numberOfKeyEntries - (index + 1);
+ final int afterLength = numberOfKeyEntries - index;
numberOfKeyEntries++;
DataRecordIdentifier[] newKeys = new DataRecordIdentifier[numberOfKeyEntries];
- long[] newPagePosition = new long[numberOfKeyEntries + 1];
- System.arraycopy(pagePositions, 0, newPagePosition, 0, index + 1);
+ long[] newPagePositions = new long[numberOfKeyEntries + 1];
if (index != 0) {
System.arraycopy(keys, 0, newKeys, 0, index);
}
- DataRecordIdentifier k = keys[index];
+ System.arraycopy(pagePositions, 0, newPagePositions, 0, index + 1);
newKeys[index] = middleKey;
- newKeys[index + 1] = k;
- System.arraycopy(pagePositions, index + 1, newPagePosition, index + 2,
- afterLength + 1);
- System.arraycopy(keys, index + 2, newKeys, index + 2, afterLength);
+ newPagePositions[index + 1] = rightSonNonTerminalPage
+ .getPositionInFile();
+
+ if (afterLength != 0) {
+ System.arraycopy(keys, index, newKeys, index + 1, afterLength);
+ System.arraycopy(pagePositions, index + 1, newPagePositions,
+ index + 2, afterLength);
+ }
+ keys = newKeys;
+ pagePositions = newPagePositions;
// ASSERTX
assert byteSize != 0 : "unknow current byte size";
- byteSize += entrySize + 8;
+ byteSize += entrySize;
// ASSERTX
assert byteSize == computeByteSize();
return byteSize < PageConstant.PAGE_SIZE;
}
- public NonTerminalPage split() {
+ public INonTerminalPage split() {
final int splitIndex = numberOfKeyEntries / 2;
middleKey = keys[splitIndex];
final int newNumberOfKeyEntries = splitIndex;
@@ -233,7 +252,7 @@
keys, splitIndex + 1, numberOfKeyEntries);
final long[] newNonTerminalPagePosition = Arrays.copyOfRange(
pagePositions, splitIndex + 1, numberOfKeyEntries + 1);
- final NonTerminalPage nonTerminalPage = new NonTerminalPage(
+ final INonTerminalPage nonTerminalPage = new NonTerminalPage(
newNonTerminalPageNumberOfKeyEntries, newNonTerminalKeys,
newNonTerminalPagePosition);
keys = newKeys;
@@ -243,7 +262,14 @@
return nonTerminalPage;
}
- public DataRecordIdentifier getMiddleKey() {
- return middleKey;
+ /**
+ * get and clear middle key computed by {@link #split()}
+ *
+ * @return middle key computed by {@link #split()}
+ */
+ public DataRecordIdentifier getAndClearMiddleKey() {
+ final DataRecordIdentifier result = middleKey;
+ middleKey = null;
+ return result;
}
}
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-24 04:44:11 UTC (rev 3029)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusDataManager.java 2012-04-25 04:28:28 UTC (rev 3030)
@@ -30,6 +30,7 @@
import net.sf.joafip.Fortest;
import net.sf.joafip.btreeplus.entity.EnumRecordType;
import net.sf.joafip.btreeplus.entity.IDataBlock;
+import net.sf.joafip.btreeplus.entity.INonTerminalPage;
import net.sf.joafip.btreeplus.entity.IPageRecordable;
import net.sf.joafip.btreeplus.entity.LeafPage;
import net.sf.joafip.btreeplus.entity.NonTerminalPage;
@@ -263,13 +264,13 @@
newLeafPage);
} else {
if (!nonTerminalPage.add(leafPage, newLeafPage)) {
- NonTerminalPage newNonTerminalPage = nonTerminalPage
+ INonTerminalPage newNonTerminalPage = nonTerminalPage
.split();
do {
btreePlusElementMgr
.appendPageRecordable(newNonTerminalPage);
DataRecordIdentifier middleKey = nonTerminalPage
- .getMiddleKey();
+ .getAndClearMiddleKey();
NonTerminalPage parent = (NonTerminalPage) nonTerminalPage
.getParentPage();
if (parent == null) {
Modified: trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java
===================================================================
--- trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-24 04:44:11 UTC (rev 3029)
+++ trunk/joafip-btreeplus/src/main/java/net/sf/joafip/btreeplus/service/BtreePlusElementMgr.java 2012-04-25 04:28:28 UTC (rev 3030)
@@ -27,6 +27,7 @@
import net.sf.joafip.btreeplus.entity.DataBlockPage;
import net.sf.joafip.btreeplus.entity.HeaderPage;
import net.sf.joafip.btreeplus.entity.IDataBlock;
+import net.sf.joafip.btreeplus.entity.INonTerminalPage;
import net.sf.joafip.btreeplus.entity.IPageRecord;
import net.sf.joafip.btreeplus.entity.IPageRecordable;
import net.sf.joafip.btreeplus.entity.LeafPage;
@@ -239,7 +240,7 @@
final LeafPage rightLeafPage) throws HeapException {
final NonTerminalPage nonTerminalPage = new NonTerminalPage(1);
nonTerminalPage.setEntry(0, leftLeafPage.getPositionInFile(),
- leftLeafPage.lastKey());
+ leftLeafPage.getLastKey());
nonTerminalPage.setEntry(1, rightLeafPage.getPositionInFile(), null);
appendPageRecordable(nonTerminalPage);
nonTerminalPage.updateByteSize();
@@ -247,9 +248,9 @@
}
public void newRootNonTerminalPage(
- final NonTerminalPage leftNonTerminalPage,
+ final INonTerminalPage leftNonTerminalPage,
final DataRecordIdentifier middleKey,
- final NonTerminalPage rightNonTerminalPage) throws HeapException {
+ final INonTerminalPage rightNonTerminalPage) throws HeapException {
final NonTerminalPage nonTerminalPage = new NonTerminalPage(1);
nonTerminalPage.setEntry(0, leftNonTerminalPage.getPositionInFile(),
middleKey);
Modified: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java 2012-04-24 04:44:11 UTC (rev 3029)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/LeafPageTest.java 2012-04-25 04:28:28 UTC (rev 3030)
@@ -25,7 +25,6 @@
import net.sf.joafip.AbstractJoafipCommonTestCase;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.StorableAccess;
import net.sf.joafip.TestException;
import net.sf.joafip.btreeplus.entity.mock.MockDataBlock;
import net.sf.joafip.btreeplus.entity.mock.MockPageRecordable;
@@ -38,7 +37,6 @@
*
*/
@NotStorableClass
-@StorableAccess
public class LeafPageTest extends AbstractJoafipCommonTestCase {
public LeafPageTest() throws TestException {
@@ -108,7 +106,7 @@
assertEquals("must not find", -1L,
leafPage.getDataBlockPosition(new DataRecordIdentifier(0)));
assertEquals("bad last key", new DataRecordIdentifier(lastKeyValue),
- leafPage.lastKey());
+ leafPage.getLastKey());
}
public void testSetDataBlock() throws HeapException {
Added: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java (rev 0)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/NonTerminalPageTest.java 2012-04-25 04:28:28 UTC (rev 3030)
@@ -0,0 +1,382 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity;
+
+import net.sf.joafip.AbstractJoafipCommonTestCase;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.StorableAccess;
+import net.sf.joafip.TestException;
+import net.sf.joafip.btreeplus.entity.mock.MockLeafPage;
+import net.sf.joafip.btreeplus.entity.mock.MockNonTerminalPage;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+@StorableAccess
+public class NonTerminalPageTest extends AbstractJoafipCommonTestCase {
+
+ public NonTerminalPageTest() throws TestException {
+ super();
+ }
+
+ public NonTerminalPageTest(final String name) throws TestException {
+ super(name);
+ }
+
+ public void testCreation() {
+ final NonTerminalPage nonTerminalPage = new NonTerminalPage();
+ assertEquals("must be empty", 0,
+ nonTerminalPage.getNumberOfKeyEntries());
+ assertEquals("must be one page", 1, nonTerminalPage.getNumberOfPage());
+ assertEquals("bad record type", EnumRecordType.NON_TERMINAL_PAGE,
+ nonTerminalPage.getRecordType());
+ assertEquals("bad byte size", byteSize(0),
+ nonTerminalPage.getByteSize());
+ }
+
+ public void testAddLeafPage() throws HeapException {
+ // A 10 B
+ final NonTerminalPage nonTerminalPage = new NonTerminalPage(1);
+ final MockLeafPage leafPageA = new MockLeafPage();
+ final long pageAPositionInFile = 1000;
+ leafPageA.setPositionInFile(pageAPositionInFile);
+ final MockLeafPage leafPageB = new MockLeafPage();
+ final long pageBPositionInFile = 2000;
+ leafPageB.setPositionInFile(pageBPositionInFile);
+ final DataRecordIdentifier key10 = new DataRecordIdentifier(10);
+ nonTerminalPage.setEntry(0, leafPageA.getPositionInFile(), key10);
+ nonTerminalPage.setEntry(1, leafPageB.getPositionInFile(), null);
+ nonTerminalPage.updateByteSize();
+
+ checkState(nonTerminalPage, new DataRecordIdentifier[] { key10 },
+ new long[] { pageAPositionInFile, pageBPositionInFile });
+ assertEquals("bad key 9 index", 0,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
+ assertEquals("bad key 11 index", 1,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
+
+ // A 10 B -> A 5 C 10 B
+ final MockLeafPage leafPageC = new MockLeafPage();
+ final long pageCPositionInFile = 3000;
+ leafPageC.setPositionInFile(pageCPositionInFile);
+ final DataRecordIdentifier key5 = new DataRecordIdentifier(5);
+ leafPageA.setLastKey(key5);
+ leafPageA.setInParentIndex(0);
+
+ nonTerminalPage.add(leafPageA, leafPageC);
+ checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key10 },
+ new long[] { pageAPositionInFile, pageCPositionInFile,
+ pageBPositionInFile });
+ assertEquals("bad key 4 index", 0,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
+ assertEquals("bad key 9 index", 1,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
+ assertEquals("bad key 11 index", 2,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
+
+ // A 5 C 10 B -> A 5 C 10 B 15 D
+ final MockLeafPage leafPageD = new MockLeafPage();
+ final long pageDPositionInFile = 4000;
+ leafPageD.setPositionInFile(pageDPositionInFile);
+ final DataRecordIdentifier key15 = new DataRecordIdentifier(15);
+ leafPageB.setLastKey(key15);
+ leafPageB.setInParentIndex(2);
+ nonTerminalPage.add(leafPageB, leafPageD);
+ checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key10,
+ key15 }, new long[] { pageAPositionInFile, pageCPositionInFile,
+ pageBPositionInFile, pageDPositionInFile });
+ assertEquals("bad key 4 index", 0,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
+ assertEquals("bad key 9 index", 1,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
+ assertEquals("bad key 11 index", 2,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
+ assertEquals("bad key 16 index", 3,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(16)));
+
+ // A 5 C 10 B 15 D -> A 5 C 7 E 10 B 15 D
+ final MockLeafPage leafPageE = new MockLeafPage();
+ final long pageEPositionInFile = 5000;
+ leafPageE.setPositionInFile(pageEPositionInFile);
+ final DataRecordIdentifier key7 = new DataRecordIdentifier(7);
+ leafPageC.setLastKey(key7);
+ leafPageC.setInParentIndex(1);
+ nonTerminalPage.add(leafPageC, leafPageE);
+ checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key7,
+ key10, key15 }, new long[] { pageAPositionInFile,
+ pageCPositionInFile, pageEPositionInFile, pageBPositionInFile,
+ pageDPositionInFile });
+ assertEquals("bad key 4 index", 0,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
+ assertEquals("bad key 6 index", 1,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(6)));
+ assertEquals("bad key 9 index", 2,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
+ assertEquals("bad key 11 index", 3,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
+ assertEquals("bad key 16 index", 4,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(16)));
+
+ // A 5 C 7 E 10 B 15 D -> A 5 C 7 E 10 B 15 D 17 F
+ final MockLeafPage leafPageF = new MockLeafPage();
+ final long pageFPositionInFile = 6000;
+ leafPageF.setPositionInFile(pageFPositionInFile);
+ final DataRecordIdentifier key17 = new DataRecordIdentifier(17);
+ leafPageD.setLastKey(key17);
+ leafPageD.setInParentIndex(4);
+ nonTerminalPage.add(leafPageD, leafPageF);
+ checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key7,
+ key10, key15, key17 }, new long[] { pageAPositionInFile,
+ pageCPositionInFile, pageEPositionInFile, pageBPositionInFile,
+ pageDPositionInFile, pageFPositionInFile });
+ assertEquals("bad key 4 index", 0,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
+ assertEquals("bad key 6 index", 1,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(6)));
+ assertEquals("bad key 9 index", 2,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
+ assertEquals("bad key 11 index", 3,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
+ assertEquals("bad key 16 index", 4,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(16)));
+ assertEquals("bad key 18 index", 5,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(18)));
+ }
+
+ public void testAddLeafPageNeedSplit() throws HeapException {
+ // A 10 B
+ final NonTerminalPage nonTerminalPage = new NonTerminalPage(1);
+ final MockLeafPage leafPageA = new MockLeafPage();
+ final long pageAPositionInFile = 1000;
+ leafPageA.setPositionInFile(pageAPositionInFile);
+ final MockLeafPage leafPageB = new MockLeafPage();
+ final long pageBPositionInFile = 2000;
+ leafPageB.setPositionInFile(pageBPositionInFile);
+ final DataRecordIdentifier key10 = new DataRecordIdentifier(10);
+ nonTerminalPage.setEntry(0, leafPageA.getPositionInFile(), key10);
+ nonTerminalPage.setEntry(1, leafPageB.getPositionInFile(), null);
+ nonTerminalPage.updateByteSize();
+
+ MockLeafPage leftPage = leafPageB;
+ final int maxNumberOfEntries = maxNumberOfEntries();
+ while (nonTerminalPage.getNumberOfKeyEntries() < maxNumberOfEntries) {
+ final MockLeafPage rightPage = new MockLeafPage();
+ leftPage.setInParentIndex(nonTerminalPage.getNumberOfKeyEntries() - 1);
+ leftPage.setLastKey(key10);
+ assertTrue("must not need split",
+ nonTerminalPage.add(leftPage, rightPage));
+ leftPage = rightPage;
+ }
+ final MockLeafPage rightPage = new MockLeafPage();
+ leftPage.setInParentIndex(nonTerminalPage.getNumberOfKeyEntries() - 1);
+ leftPage.setLastKey(key10);
+ assertFalse("must need split", nonTerminalPage.add(leftPage, rightPage));
+ }
+
+ public void testAddNonTerminalPage() throws HeapException {
+ // A 10 B
+ final NonTerminalPage nonTerminalPage = new NonTerminalPage(1);
+ final MockNonTerminalPage pageA = new MockNonTerminalPage();
+ final long pageAPositionInFile = 1000;
+ pageA.setPositionInFile(pageAPositionInFile);
+ final MockNonTerminalPage pageB = new MockNonTerminalPage();
+ final long pageBPositionInFile = 2000;
+ pageB.setPositionInFile(pageBPositionInFile);
+ final DataRecordIdentifier key10 = new DataRecordIdentifier(10);
+ nonTerminalPage.setEntry(0, pageA.getPositionInFile(), key10);
+ nonTerminalPage.setEntry(1, pageB.getPositionInFile(), null);
+ nonTerminalPage.updateByteSize();
+
+ checkState(nonTerminalPage, new DataRecordIdentifier[] { key10 },
+ new long[] { pageAPositionInFile, pageBPositionInFile });
+ assertEquals("bad key 9 index", 0,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
+ assertEquals("bad key 11 index", 1,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
+
+ // A 10 B -> A 5 C 10 B
+ final MockNonTerminalPage pageC = new MockNonTerminalPage();
+ final long pageCPositionInFile = 3000;
+ pageC.setPositionInFile(pageCPositionInFile);
+ final DataRecordIdentifier key5 = new DataRecordIdentifier(5);
+ pageA.setInParentIndex(0);
+ nonTerminalPage.add(pageA, key5, pageC);
+ checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key10 },
+ new long[] { pageAPositionInFile, pageCPositionInFile,
+ pageBPositionInFile });
+ assertEquals("bad key 4 index", 0,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
+ assertEquals("bad key 9 index", 1,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
+ assertEquals("bad key 11 index", 2,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
+
+ // ------------
+ // A 5 C 10 B -> A 5 C 10 B 15 D
+ final MockNonTerminalPage pageD = new MockNonTerminalPage();
+ final long pageDPositionInFile = 4000;
+ pageD.setPositionInFile(pageDPositionInFile);
+ final DataRecordIdentifier key15 = new DataRecordIdentifier(15);
+ pageB.setInParentIndex(2);
+ nonTerminalPage.add(pageB, key15, pageD);
+ checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key10,
+ key15 }, new long[] { pageAPositionInFile, pageCPositionInFile,
+ pageBPositionInFile, pageDPositionInFile });
+ assertEquals("bad key 4 index", 0,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
+ assertEquals("bad key 9 index", 1,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
+ assertEquals("bad key 11 index", 2,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
+ assertEquals("bad key 16 index", 3,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(16)));
+
+ // A 5 C 10 B 15 D -> A 5 C 7 E 10 B 15 D
+ final MockNonTerminalPage pageE = new MockNonTerminalPage();
+ final long pageEPositionInFile = 5000;
+ pageE.setPositionInFile(pageEPositionInFile);
+ final DataRecordIdentifier key7 = new DataRecordIdentifier(7);
+ pageC.setInParentIndex(1);
+ nonTerminalPage.add(pageC, key7, pageE);
+ checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key7,
+ key10, key15 }, new long[] { pageAPositionInFile,
+ pageCPositionInFile, pageEPositionInFile, pageBPositionInFile,
+ pageDPositionInFile });
+ assertEquals("bad key 4 index", 0,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
+ assertEquals("bad key 6 index", 1,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(6)));
+ assertEquals("bad key 9 index", 2,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
+ assertEquals("bad key 11 index", 3,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
+ assertEquals("bad key 16 index", 4,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(16)));
+
+ // A 5 C 7 E 10 B 15 D -> A 5 C 7 E 10 B 15 D 17 F
+ final MockNonTerminalPage pageF = new MockNonTerminalPage();
+ final long pageFPositionInFile = 6000;
+ pageF.setPositionInFile(pageFPositionInFile);
+ final DataRecordIdentifier key17 = new DataRecordIdentifier(17);
+ pageD.setInParentIndex(4);
+ nonTerminalPage.add(pageD, key17, pageF);
+ checkState(nonTerminalPage, new DataRecordIdentifier[] { key5, key7,
+ key10, key15, key17 }, new long[] { pageAPositionInFile,
+ pageCPositionInFile, pageEPositionInFile, pageBPositionInFile,
+ pageDPositionInFile, pageFPositionInFile });
+ assertEquals("bad key 4 index", 0,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(4)));
+ assertEquals("bad key 6 index", 1,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(6)));
+ assertEquals("bad key 9 index", 2,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(9)));
+ assertEquals("bad key 11 index", 3,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(11)));
+ assertEquals("bad key 16 index", 4,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(16)));
+ assertEquals("bad key 18 index", 5,
+ nonTerminalPage.getIndex(new DataRecordIdentifier(18)));
+
+ }
+
+ public void testAddNonTerminalPageNeedSplit() throws HeapException {
+ // A 10 B
+ final NonTerminalPage nonTerminalPage = new NonTerminalPage(1);
+ final MockNonTerminalPage pageA = new MockNonTerminalPage();
+ final long pageAPositionInFile = 1000;
+ pageA.setPositionInFile(pageAPositionInFile);
+ final MockNonTerminalPage pageB = new MockNonTerminalPage();
+ final long pageBPositionInFile = 2000;
+ pageB.setPositionInFile(pageBPositionInFile);
+ final DataRecordIdentifier key10 = new DataRecordIdentifier(10);
+ nonTerminalPage.setEntry(0, pageA.getPositionInFile(), key10);
+ nonTerminalPage.setEntry(1, pageB.getPositionInFile(), null);
+ nonTerminalPage.updateByteSize();
+
+ MockNonTerminalPage leftPage = pageB;
+ final int maxNumberOfEntries = maxNumberOfEntries();
+ while (nonTerminalPage.getNumberOfKeyEntries() < maxNumberOfEntries) {
+ final MockNonTerminalPage rightPage = new MockNonTerminalPage();
+ leftPage.setInParentIndex(nonTerminalPage.getNumberOfKeyEntries() - 1);
+ assertTrue("must not need split",
+ nonTerminalPage.add(leftPage, key10, rightPage));
+ leftPage = rightPage;
+ }
+ final MockNonTerminalPage rightPage = new MockNonTerminalPage();
+ leftPage.setInParentIndex(nonTerminalPage.getNumberOfKeyEntries() - 1);
+ assertFalse("must need split",
+ nonTerminalPage.add(leftPage, key10, rightPage));
+ }
+
+ public void testSplit() {
+
+ }
+
+ public void testSetEntry() {
+
+ }
+
+ public void testSetParentPage() {
+
+ }
+
+ private void checkState(final NonTerminalPage nonTerminalPage,
+ final DataRecordIdentifier[] keys, final long[] pointers) {
+ final int numberOfEntries = keys.length;
+ assertEquals("bad byte size", byteSize(numberOfEntries),
+ nonTerminalPage.getByteSize());
+ assertEquals("must has " + numberOfEntries + " entries",
+ numberOfEntries, nonTerminalPage.getNumberOfKeyEntries());
+ for (int index = 0; index < numberOfEntries; index++) {
+ assertEquals("bad index", index,
+ nonTerminalPage.getIndex(keys[index]));
+ assertEquals("bad key #0", keys[index],
+ nonTerminalPage.getKey(index));
+ assertEquals("bad #" + index + " page pointer", pointers[index],
+ nonTerminalPage.getPagePointer(index));
+ }
+ assertEquals("bad #" + numberOfEntries + " page pointer",
+ pointers[numberOfEntries],
+ nonTerminalPage.getPagePointer(numberOfEntries));
+ }
+
+ private int byteSize(final int numberOfKeyEntries) {
+ int xbyteSize = 1/* byte size for record type */+
+ /**/4/* int size for number of entries */+
+ /**/4/* int size for crc32 */+
+ /**/numberOfKeyEntries * 8/* key entries */+
+ /**/(numberOfKeyEntries + 1) * 8/* pointers entries */;
+ // FIXMELUC ______speedup if long value key
+ return xbyteSize;
+ }
+
+ private int maxNumberOfEntries() {
+ return (int) ((PageConstant.PAGE_SIZE - (1 + 4 + 4 + 8)) / (8 * 2));
+ }
+}
Added: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java (rev 0)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockLeafPage.java 2012-04-25 04:28:28 UTC (rev 3030)
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity.mock;
+
+import net.sf.joafip.btreeplus.entity.EnumRecordType;
+import net.sf.joafip.btreeplus.entity.ILeafPage;
+import net.sf.joafip.btreeplus.entity.IPageRecord;
+import net.sf.joafip.btreeplus.entity.IPageRecordable;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class MockLeafPage implements ILeafPage {
+
+ private long positionInFile;
+ private DataRecordIdentifier lastKey;
+ private int inParentIndex;
+
+ @Override
+ public EnumRecordType getRecordType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getNumberOfPage() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public int getByteSize() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void updateByteSize() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public IPageRecord getPageRecord() throws HeapException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setPageRecord(IPageRecord pageRecord) throws HeapException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setParentPage(IPageRecordable parentPage, int inParentIndex)
+ throws HeapException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public IPageRecordable getParentPage() throws HeapException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setInParentIndex(final int inParentIndex) {
+ this.inParentIndex = inParentIndex;
+ }
+
+ @Override
+ public int getInParentIndex() throws HeapException {
+ return inParentIndex;
+ }
+
+ @Override
+ public void setValueIsChangedValueToSave() throws HeapException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setValueIsNotChanged() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setLastKey(final DataRecordIdentifier lastKey) {
+ this.lastKey = lastKey;
+ }
+
+ @Override
+ public DataRecordIdentifier getLastKey() {
+ return lastKey;
+ }
+
+ public void setPositionInFile(final long positionInFile) {
+ this.positionInFile = positionInFile;
+ }
+
+ @Override
+ public long getPositionInFile() {
+ return positionInFile;
+ }
+}
Added: trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java
===================================================================
--- trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java (rev 0)
+++ trunk/joafip-btreeplus/src/test/java/net/sf/joafip/btreeplus/entity/mock/MockNonTerminalPage.java 2012-04-25 04:28:28 UTC (rev 3030)
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.btreeplus.entity.mock;
+
+import net.sf.joafip.btreeplus.entity.EnumRecordType;
+import net.sf.joafip.btreeplus.entity.INonTerminalPage;
+import net.sf.joafip.btreeplus.entity.IPageRecord;
+import net.sf.joafip.btreeplus.entity.IPageRecordable;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class MockNonTerminalPage implements INonTerminalPage {
+
+ private long positionInFile;
+ private int inParentIndex;
+
+ @Override
+ public EnumRecordType getRecordType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getNumberOfPage() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public int getByteSize() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void updateByteSize() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public IPageRecord getPageRecord() throws HeapException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setPageRecord(IPageRecord pageRecord) throws HeapException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setParentPage(IPageRecordable parentPage, int inParentIndex)
+ throws HeapException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public IPageRecordable getParentPage() throws HeapException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setValueIsChangedValueToSave() throws HeapException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setValueIsNotChanged() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setInParentIndex(final int inParentIndex) {
+ this.inParentIndex = inParentIndex;
+ }
+
+ @Override
+ public int getInParentIndex() throws HeapException {
+ return inParentIndex;
+ }
+
+ public void setPositionInFile(final long positionInFile) {
+ this.positionInFile = positionInFile;
+ }
+
+ @Override
+ public long getPositionInFile() {
+ return positionInFile;
+ }
+
+}
Modified: trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/BtreePlusEntityTests.java
===================================================================
--- trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/BtreePlusEntityTests.java 2012-04-24 04:44:11 UTC (rev 3029)
+++ trunk/joafip-testsuite/src/main/java/net/sf/joafip/btreeplus/entity/BtreePlusEntityTests.java 2012-04-25 04:28:28 UTC (rev 3030)
@@ -43,8 +43,7 @@
final TestSuite suite = new TestSuite("Test for btree plus entity");
// $JUnit-BEGIN$
suite.addTestSuite(LeafPageTest.class);
- // suite.addTestSuite(RandomAccessFileReadWriteCacheTest.class);
- // suite.addTestSuite(TestRandomAccessFileCache.class);
+ suite.addTestSuite(NonTerminalPageTest.class);
// $JUnit-END$
return suite;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|