Thread: [Joafip-svn] SF.net SVN: joafip:[2999] trunk (Page 3)
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2012-04-09 05:41:32
|
Revision: 2999
http://joafip.svn.sourceforge.net/joafip/?rev=2999&view=rev
Author: luc_peuvrier
Date: 2012-04-09 05:41:25 +0000 (Mon, 09 Apr 2012)
Log Message:
-----------
data manager using jdbm library
Modified Paths:
--------------
trunk/joafip-4test/pom.xml
trunk/joafip-common/src/main/java/net/sf/joafip/logger/DummyLogger.java
trunk/joafip-common/src/main/java/net/sf/joafip/logger/JoafipLogger.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMemoryDataManagerMock.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMultiFileDataManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java
trunk/joafip-parent/pom.xml
Added Paths:
-----------
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java
trunk/joafip-jdbm/.classpath
trunk/joafip-jdbm/.pmd
trunk/joafip-jdbm/.project
trunk/joafip-jdbm/.ruleset
trunk/joafip-jdbm/.settings/
trunk/joafip-jdbm/.settings/org.eclipse.core.resources.prefs
trunk/joafip-jdbm/.settings/org.eclipse.jdt.core.prefs
trunk/joafip-jdbm/.settings/org.eclipse.m2e.core.prefs
trunk/joafip-jdbm/pom.xml
trunk/joafip-jdbm/src/
trunk/joafip-jdbm/src/main/
trunk/joafip-jdbm/src/main/java/
trunk/joafip-jdbm/src/main/java/net/
trunk/joafip-jdbm/src/main/java/net/sf/
trunk/joafip-jdbm/src/main/java/net/sf/joafip/
trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/
trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/entity/
trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/
trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java
trunk/joafip-jdbm/src/main/resources/
trunk/joafip-jdbm/src/test/
trunk/joafip-jdbm/src/test/java/
trunk/joafip-jdbm/src/test/resources/
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java
trunk/joafip-log4j/src/test/java/net/
trunk/joafip-log4j/src/test/java/net/sf/
trunk/joafip-log4j/src/test/java/net/sf/joafip/
trunk/joafip-log4j/src/test/java/net/sf/joafip/logger/
trunk/joafip-log4j/src/test/java/net/sf/joafip/logger/TestCreateLogger.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractHeapDataManager.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-09 05:41:34
|
Revision: 2999
http://joafip.svn.sourceforge.net/joafip/?rev=2999&view=rev
Author: luc_peuvrier
Date: 2012-04-09 05:41:25 +0000 (Mon, 09 Apr 2012)
Log Message:
-----------
data manager using jdbm library
Modified Paths:
--------------
trunk/joafip-4test/pom.xml
trunk/joafip-common/src/main/java/net/sf/joafip/logger/DummyLogger.java
trunk/joafip-common/src/main/java/net/sf/joafip/logger/JoafipLogger.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMemoryDataManagerMock.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapMultiFileDataManager.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IHeapDataManager.java
trunk/joafip-parent/pom.xml
Added Paths:
-----------
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java
trunk/joafip-jdbm/.classpath
trunk/joafip-jdbm/.pmd
trunk/joafip-jdbm/.project
trunk/joafip-jdbm/.ruleset
trunk/joafip-jdbm/.settings/
trunk/joafip-jdbm/.settings/org.eclipse.core.resources.prefs
trunk/joafip-jdbm/.settings/org.eclipse.jdt.core.prefs
trunk/joafip-jdbm/.settings/org.eclipse.m2e.core.prefs
trunk/joafip-jdbm/pom.xml
trunk/joafip-jdbm/src/
trunk/joafip-jdbm/src/main/
trunk/joafip-jdbm/src/main/java/
trunk/joafip-jdbm/src/main/java/net/
trunk/joafip-jdbm/src/main/java/net/sf/
trunk/joafip-jdbm/src/main/java/net/sf/joafip/
trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/
trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/entity/
trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/
trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java
trunk/joafip-jdbm/src/main/resources/
trunk/joafip-jdbm/src/test/
trunk/joafip-jdbm/src/test/java/
trunk/joafip-jdbm/src/test/resources/
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java
trunk/joafip-log4j/src/test/java/net/
trunk/joafip-log4j/src/test/java/net/sf/
trunk/joafip-log4j/src/test/java/net/sf/joafip/
trunk/joafip-log4j/src/test/java/net/sf/joafip/logger/
trunk/joafip-log4j/src/test/java/net/sf/joafip/logger/TestCreateLogger.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractHeapDataManager.java
Modified: trunk/joafip-4test/pom.xml
===================================================================
--- trunk/joafip-4test/pom.xml 2012-04-09 05:37:59 UTC (rev 2998)
+++ trunk/joafip-4test/pom.xml 2012-04-09 05:41:25 UTC (rev 2999)
@@ -51,6 +51,12 @@
<dependency>
<groupId>net.sf.joafip</groupId>
+ <artifactId>joafip-jdbm</artifactId>
+ <version>4.0.0b8</version>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sf.joafip</groupId>
<artifactId>joafip-rbtree</artifactId>
<version>4.0.0b8</version>
</dependency>
Added: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java 2012-04-09 05:41:25 UTC (rev 2999)
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2011 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.performance.items.service;//NOPMD
+
+import java.io.File;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.StorableAccess;
+import net.sf.joafip.jdbm.service.JdbmDataManager;
+import net.sf.joafip.kvstore.service.IHeapDataManager;
+import net.sf.joafip.logger.JoafipLogger;
+import net.sf.joafip.service.FilePersistenceClassNotFoundException;
+import net.sf.joafip.service.FilePersistenceDataCorruptedException;
+import net.sf.joafip.service.FilePersistenceException;
+import net.sf.joafip.service.FilePersistenceInvalidClassException;
+import net.sf.joafip.service.FilePersistenceNotSerializableException;
+import net.sf.joafip.service.FilePersistenceTooBigForSerializationException;
+import net.sf.joafip.store.service.StoreClassNotFoundException;
+
+@SuppressWarnings("PMD")
+@NotStorableClass
+@StorableAccess
+public class InserterJdbm extends AbstractInserter {
+
+ private static final JoafipLogger LOGGER = JoafipLogger
+ .getLogger(InserterJdbm.class);
+
+ public InserterJdbm(final IHeapDataManager dataManager) throws FilePersistenceException,
+ FilePersistenceInvalidClassException,
+ FilePersistenceNotSerializableException,
+ FilePersistenceClassNotFoundException,
+ FilePersistenceDataCorruptedException, StoreClassNotFoundException,
+ FilePersistenceTooBigForSerializationException {
+ super(dataManager);
+ }
+
+ public static void main(final String[] args) {
+ /* remove existing data */
+ final File dataDirectory = new File(RUNTIME_DIR);
+ for (final File file : dataDirectory.listFiles()) {
+ file.delete();
+ }
+ dataDirectory.mkdirs();
+ InserterJdbm inserter;
+ try {
+ final JdbmDataManager bananaDataManager=new JdbmDataManager((new File(dataDirectory,"banana.data")).getAbsolutePath());
+ inserter = new InserterJdbm(bananaDataManager);
+ inserter.run(NUMBER_OF_ITEM);
+ inserter.close();
+ } catch (final Throwable throwable) {// NOPMD catch all
+ LOGGER.fatal("error", throwable);
+ }
+ }
+}
Modified: trunk/joafip-common/src/main/java/net/sf/joafip/logger/DummyLogger.java
===================================================================
--- trunk/joafip-common/src/main/java/net/sf/joafip/logger/DummyLogger.java 2012-04-09 05:37:59 UTC (rev 2998)
+++ trunk/joafip-common/src/main/java/net/sf/joafip/logger/DummyLogger.java 2012-04-09 05:41:25 UTC (rev 2999)
@@ -27,66 +27,73 @@
* @author luc peuvrier
*
*/
+@SuppressWarnings("PMD")
public class DummyLogger implements IJoafipLogger {
@Override
public void debug(final Object message) {
- // no implementation
+ System.err.println("debug: "+message);
}
@Override
public void debug(final Object message, final Throwable throwable) {
- // no implementation
+ System.err.println("debug: "+message);
+ throwable.printStackTrace();
}
@Override
public void trace(final Object message) {
- // no implementation
+ System.err.println("trace: "+message);
}
@Override
public void trace(final Object message, final Throwable throwable) {
- // no implementation
+ System.err.println("trace: "+message);
+ throwable.printStackTrace();
}
@Override
public void info(final Object message) {
- // no implementation
+ System.err.println("info: "+message);
}
@Override
public void info(final Object message, final Throwable throwable) {
- // no implementation
+ System.err.println("info: "+message);
+ throwable.printStackTrace();
}
@Override
public void warn(final Object message) {
- // no implementation
+ System.err.println("warn: "+message);
}
@Override
public void warn(final Object message, final Throwable throwable) {
- // no implementation
+ System.err.println("warn: "+message);
+ throwable.printStackTrace();
}
@Override
public void error(final Object message) {
- // no implementation
+ System.err.println("error: "+message);
}
@Override
public void error(final Object message, final Throwable throwable) {
- // no implementation
+ System.err.println("error: "+message);
+ throwable.printStackTrace();
}
@Override
public void fatal(final Object message) {
- // no implementation
+ System.err.println("fatal: "+message);
}
@Override
public void fatal(final Object message, final Throwable throwable) {
- // no implementation
+ System.err.println("fatal: "+message);
+ throwable.printStackTrace();
}
@Override
Modified: trunk/joafip-common/src/main/java/net/sf/joafip/logger/JoafipLogger.java
===================================================================
--- trunk/joafip-common/src/main/java/net/sf/joafip/logger/JoafipLogger.java 2012-04-09 05:37:59 UTC (rev 2998)
+++ trunk/joafip-common/src/main/java/net/sf/joafip/logger/JoafipLogger.java 2012-04-09 05:41:25 UTC (rev 2999)
@@ -65,8 +65,9 @@
}
if (inStream == null) {
System.err.println(// NOPMD
- /**/"failed to find " + JOAFIP_LOGGER_PROPERTIES
- + " resource");
+ /**/JoafipLogger.class.getName()
+ + ": failed to find "
+ + JOAFIP_LOGGER_PROPERTIES + " resource");
loggerFactory = new DummyLoggerFactory();
} else {
final Properties properties = new Properties();
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractHeapDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractHeapDataManager.java 2012-04-09 05:37:59 UTC (rev 2998)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractHeapDataManager.java 2012-04-09 05:41:25 UTC (rev 2999)
@@ -1,701 +0,0 @@
-/*
- * Copyright 2008 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.service;
-
-import java.io.Serializable;
-import java.util.Iterator;
-import java.util.Set;
-
-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.IHeapDataManager;
-import net.sf.joafip.logger.JoafipLogger;
-
-/**
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public abstract class AbstractHeapDataManager implements IHeapDataManager,
- Serializable {
-
- private static final String UNSUPPORTED_OPERATION = "unsupported operation";
-
- /**
- *
- */
- private static final long serialVersionUID = -2448517084972656682L;
-
- protected final JoafipLogger logger = JoafipLogger.getLogger(getClass());// NOPMD
-
- private static final String DATA_MANAGER_NOT_OPENED =
- /**/"data manager not opened";
-
- private static final String DATA_MANAGER_ALREADY_OPENED =
- /**/"data manager already opened";
-
- protected static final String FLUSH_FAILED =
- /**/"flush failed";
-
- protected static final String FAILED_READ_DATA_RECORD =
- /**/"failed read data record for identifier ";
-
- protected static final String CLEAR_STANDBY_MODIFICATION_FAILED =
- /**/"clear standby modification failed";
-
- /** true when this is service started state */
- private boolean started = false;
-
- private Exception stopperStackTrace = new Exception("stopper stack trace");// NOPMD
-
- private Exception starterStackTrace = null;
-
- @Override
- final public void startService(final boolean removeFiles)
- throws HeapException {
- try {
- // ASSERTX
- assert assertStopped();
- if (removeFiles) {
- removeFiles();
- if (logger.debugEnabled) {
- logger.debug("remove files");
- }
- }
- startServiceImpl(removeFiles);
- started = true;
- starterStackTrace = new Exception("starter stack trace");// NOPMD
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- /**
- * remove existing files
- *
- * @throws HeapException
- */
- protected abstract void removeFiles() throws HeapException;
-
- /**
- * to implement open actions
- *
- * @param removeFiles
- * @throws HeapException
- */
- protected abstract void startServiceImpl(final boolean removeFiles)
- throws HeapException;
-
- @Override
- final public void stopService() throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- started = false;
- stopperStackTrace = new Exception("stopper stack trace");// NOPMD
- stopServiceImpl();
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- /**
- * to implement close actions
- *
- * @throws HeapException
- */
- protected abstract void stopServiceImpl() throws HeapException;
-
- @Override
- public boolean isServiceStarted() {
- return started;
- }
-
- @Override
- public void clear() throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- clearImpl();
- if (logger.debugEnabled) {
- logger.debug("clear");
- }
- } catch (HeapException exception) {
- logger.fatal(CLEAR_STANDBY_MODIFICATION_FAILED);
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected abstract void clearImpl() throws HeapException;
-
- @Override
- public void flush() throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- flushImp();
- if (logger.debugEnabled) {
- logger.debug("flush");
- }
- } catch (HeapException exception) {
- logger.fatal(CLEAR_STANDBY_MODIFICATION_FAILED);
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- /**
- * implement all flush action after call to
- * {@link #updateHeapRecordImpl(DataRecordIdentifier, IHeapDataRecord)}
- *
- * @throws HeapException
- */
- protected abstract void flushImp() throws HeapException;
-
- @Override
- public void clearStandbyModification() throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- clearStandbyModificationImpl();
- if (logger.debugEnabled) {
- logger.debug("clear standby modification");
- }
- } catch (HeapException exception) {
- logger.fatal(CLEAR_STANDBY_MODIFICATION_FAILED);
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected abstract void clearStandbyModificationImpl() throws HeapException;
-
- @Override
- public DataRecordIdentifier getNextFreeDataRecordIdentifier()
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return getNextFreeDataRecordIdentifierImpl();
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected abstract DataRecordIdentifier getNextFreeDataRecordIdentifierImpl()
- throws HeapException;
-
- @Override
- public void setNextFreeDataRecordIdentifier(
- final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- setNextFreeDataRecordIdentifierImpl(dataRecordIdentifier);
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected abstract void setNextFreeDataRecordIdentifierImpl(
- DataRecordIdentifier dataRecordIdentifier) throws HeapException;
-
- @Override
- public DataRecordIdentifier getNewDataRecordIdentifier()
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- final DataRecordIdentifier newDataRecordIdentifier = getNewDataRecordIdentifierImpl();
- if (logger.debugEnabled) {
- logger.debug("new;" + newDataRecordIdentifier);
- }
- return newDataRecordIdentifier;
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- /**
- * to get a new data identifier for future data record creation<br>
- *
- * @return the new data record identifier
- * @throws HeapException
- */
- protected abstract DataRecordIdentifier getNewDataRecordIdentifierImpl()
- throws HeapException;
-
- @Override
- public boolean deleteDataRecord(
- final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- final boolean deleted = deleteDataRecordImpl(dataRecordIdentifier);
- if (logger.debugEnabled) {
- logger.debug("delete;" + dataRecordIdentifier);
- }
- return deleted;
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected abstract boolean deleteDataRecordImpl(
- DataRecordIdentifier dataRecordIdentifier) throws HeapException;
-
- @Override
- public byte[] readDataRecord(final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- final byte[] data = readDataRecordImpl(dataRecordIdentifier);
- if (logger.debugEnabled) {
- logger.debug("read;" + dataRecordIdentifier + ";"
- + dataToString(data));
- }
- return data;
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected abstract byte[] readDataRecordImpl(
- DataRecordIdentifier dataRecordIdentifier) throws HeapException;
-
- @Override
- public boolean writeDataRecord(
- final DataRecordIdentifier dataRecordIdentifier, final byte[] data)
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- final boolean created = writeDataRecordImpl(dataRecordIdentifier,
- data);
- if (logger.debugEnabled) {
- logger.debug("write;" + dataRecordIdentifier + ";"
- + dataToString(data));
- }
- return created;
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- /**
- *
- * @param dataRecordIdentifier
- * @param data
- * @return true if data record created
- * @throws HeapException
- */
- protected abstract boolean writeDataRecordImpl(
- DataRecordIdentifier dataRecordIdentifier, byte[] data)
- throws HeapException;
-
- @Override
- public boolean hasDataRecord(final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return hasDataRecordImpl(dataRecordIdentifier);
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected abstract boolean hasDataRecordImpl(
- final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException;
-
- @Override
- public DataRecordIdentifier firstDataRecordIdentifier()
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return firstDataRecordIdentifierImpl();
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected DataRecordIdentifier firstDataRecordIdentifierImpl()
- throws HeapException {
- throw new HeapException(UNSUPPORTED_OPERATION);
- }
-
- @Override
- public DataRecordIdentifier lastDataRecordIdentifier() throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return lastDataRecordIdentifierImpl();
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected DataRecordIdentifier lastDataRecordIdentifierImpl()
- throws HeapException {
- throw new HeapException(UNSUPPORTED_OPERATION);
- }
-
- @Override
- public DataRecordIdentifier lowerDataRecordIdentifier(
- final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return lowerDataRecordIdentifierImpl(dataRecordIdentifier);
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected DataRecordIdentifier lowerDataRecordIdentifierImpl(
- final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- throw new HeapException(UNSUPPORTED_OPERATION);
- }
-
- @Override
- public DataRecordIdentifier floorDataRecordIdentifier(
- final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return floorDataRecordIdentifierImpl(dataRecordIdentifier);
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected DataRecordIdentifier floorDataRecordIdentifierImpl(
- final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- throw new HeapException(UNSUPPORTED_OPERATION);
- }
-
- @Override
- public DataRecordIdentifier ceilingDataRecordIdentifier(
- final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return ceilingDataRecordIdentifierImpl(dataRecordIdentifier);
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected DataRecordIdentifier ceilingDataRecordIdentifierImpl(
- final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- throw new HeapException(UNSUPPORTED_OPERATION);
- }
-
- @Override
- public DataRecordIdentifier higherDataRecordIdentifier(
- final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return higherDataRecordIdentifierImpl(dataRecordIdentifier);
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected DataRecordIdentifier higherDataRecordIdentifierImpl(
- final DataRecordIdentifier dataRecordIdentifier)
- throws HeapException {
- throw new HeapException(UNSUPPORTED_OPERATION);
- }
-
- @Override
- public DataRecordIdentifier removeFirstDataRecord() throws HeapException {
- // ASSERTX
- try {
- assert assertStarted();
- return removeFirstDataRecordImpl();
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected abstract DataRecordIdentifier removeFirstDataRecordImpl()
- throws HeapException;
-
- @Override
- public int getNumberOfDataRecord() throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return getNumberOfDataRecordImpl();
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- /**
- *
- * @return number of data record in heap file
- * @throws HeapException
- */
- protected abstract int getNumberOfDataRecordImpl() throws HeapException;
-
- @Override
- public int getNumberOfFreeRecord() throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return getNumberOfFreeRecordImpl();
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected abstract int getNumberOfFreeRecordImpl() throws HeapException;
-
- @Override
- public long heapSize() throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return heapSizeImpl();
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected abstract long heapSizeImpl() throws HeapException;
-
- @Override
- public long freeSize() throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return freeSizeImpl();
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- protected abstract long freeSizeImpl() throws HeapException;
-
- @Override
- public long usedSize() throws HeapException {
- try {
- // ASSERTX
- assert assertStarted();
- return usedSizeImpl();
- } catch (HeapException exception) {
- closeHeapManagerAfterException();
- throw exception;
- } catch (RuntimeException exception) {
- closeHeapManagerAfterException();
- throw exception;
- }
- }
-
- 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();
-
- /**
- * assert the data management service is started
- *
- * @throws HeapException
- */
- private boolean assertStarted() throws HeapException {
- if (!started) {
- if (logger.debugEnabled) {
- logger.debug("closer stack trace", stopperStackTrace);
- }
- throw new HeapException(DATA_MANAGER_NOT_OPENED, stopperStackTrace);
- }
- return true;
- }
-
- /**
- * assert the data management service is stopped
- *
- * @throws HeapException
- */
- private boolean assertStopped() throws HeapException {
- if (started) {
- if (logger.debugEnabled) {
- logger.debug("openner stack trace", starterStackTrace);
- }
- throw new HeapException(DATA_MANAGER_ALREADY_OPENED,
- starterStackTrace);
- }
- return true;
- }
-
- /**
- * close heap element manager after exception
- *
- */
- protected abstract void closeHeapManagerAfterException();
-
- private String dataToString(final byte data[]) {
- final StringBuilder builder = new StringBuilder();
- if (data != null) {
- for (byte byteValue : data) {
- builder.append(String.format("%02X", (int) byteValue));
- }
- }
- return builder.toString();
- }
-}
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-09 05:37:59 UTC (rev 2998)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-09 05:41:25 UTC (rev 2999)
@@ -39,6 +39,7 @@
import net.sf.joafip.kvstore.entity.EnumFileState;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
+import net.sf.joafip.kvstore.service.AbstractHeapDataManager;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTNode;
import net.sf.joafip.redblacktree.service.IRBTVisitor;
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java 2012-04-09 05:37:59 UTC (rev 2998)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/BlockDataManager.java 2012-04-09 05:41:25...
[truncated message content] |
|
From: <luc...@us...> - 2012-04-10 01:24:34
|
Revision: 3000
http://joafip.svn.sourceforge.net/joafip/?rev=3000&view=rev
Author: luc_peuvrier
Date: 2012-04-10 01:24:27 +0000 (Tue, 10 Apr 2012)
Log Message:
-----------
data manager using babudb library
Modified Paths:
--------------
trunk/joafip-4test/pom.xml
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java
trunk/joafip-common/src/main/java/net/sf/joafip/logger/JoafipLogger.java
trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java
trunk/joafip-log4j/src/main/java/net/sf/joafip/logger/Log4jAdapter.java
trunk/joafip-log4j/src/test/java/net/sf/joafip/logger/TestCreateLogger.java
trunk/joafip-parent/pom.xml
Added Paths:
-----------
trunk/joafip-4test/src/main/java/net/sf/joafip/logger/
trunk/joafip-4test/src/main/java/net/sf/joafip/logger/MainTestLogger.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterBabuDB.java
trunk/joafip-4test/src/main/resources/log4j.properties
trunk/joafip-4test/src/test/java/net/
trunk/joafip-4test/src/test/java/net/sf/
trunk/joafip-4test/src/test/java/net/sf/joafip/
trunk/joafip-4test/src/test/java/net/sf/joafip/logger/
trunk/joafip-4test/src/test/java/net/sf/joafip/logger/TestCreateLogger.java
Modified: trunk/joafip-4test/pom.xml
===================================================================
--- trunk/joafip-4test/pom.xml 2012-04-09 05:41:25 UTC (rev 2999)
+++ trunk/joafip-4test/pom.xml 2012-04-10 01:24:27 UTC (rev 3000)
@@ -57,6 +57,12 @@
<dependency>
<groupId>net.sf.joafip</groupId>
+ <artifactId>joafip-babudb</artifactId>
+ <version>4.0.0b8</version>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sf.joafip</groupId>
<artifactId>joafip-rbtree</artifactId>
<version>4.0.0b8</version>
</dependency>
@@ -89,7 +95,6 @@
<groupId>net.sf.joafip</groupId>
<artifactId>joafip-log4j</artifactId>
<version>4.0.0b8</version>
- <scope>test</scope>
</dependency>
</dependencies>
Added: trunk/joafip-4test/src/main/java/net/sf/joafip/logger/MainTestLogger.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/logger/MainTestLogger.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/logger/MainTestLogger.java 2012-04-10 01:24:27 UTC (rev 3000)
@@ -0,0 +1,32 @@
+/*
+ * 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.logger;
+
+public class MainTestLogger {
+
+ public static void main(final String[] args) {
+ final JoafipLogger logger=JoafipLogger.getLogger(MainTestLogger.class);
+ logger.fatal("fatal error message");
+ }
+}
Added: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterBabuDB.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterBabuDB.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterBabuDB.java 2012-04-10 01:24:27 UTC (rev 3000)
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2011 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.performance.items.service;//NOPMD
+
+import java.io.File;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.StorableAccess;
+import net.sf.joafip.babudb.service.BabudbDataManager;
+import net.sf.joafip.kvstore.service.IHeapDataManager;
+import net.sf.joafip.logger.JoafipLogger;
+import net.sf.joafip.service.FilePersistenceClassNotFoundException;
+import net.sf.joafip.service.FilePersistenceDataCorruptedException;
+import net.sf.joafip.service.FilePersistenceException;
+import net.sf.joafip.service.FilePersistenceInvalidClassException;
+import net.sf.joafip.service.FilePersistenceNotSerializableException;
+import net.sf.joafip.service.FilePersistenceTooBigForSerializationException;
+import net.sf.joafip.store.service.StoreClassNotFoundException;
+
+@SuppressWarnings("PMD")
+@NotStorableClass
+@StorableAccess
+public class InserterBabuDB extends AbstractInserter {
+
+ private static final JoafipLogger LOGGER = JoafipLogger
+ .getLogger(InserterBabuDB.class);
+
+ public InserterBabuDB(final IHeapDataManager dataManager) throws FilePersistenceException,
+ FilePersistenceInvalidClassException,
+ FilePersistenceNotSerializableException,
+ FilePersistenceClassNotFoundException,
+ FilePersistenceDataCorruptedException, StoreClassNotFoundException,
+ FilePersistenceTooBigForSerializationException {
+ super(dataManager);
+ }
+
+ public static void main(final String[] args) {
+ /* remove existing data */
+ final File dataDirectory = new File(RUNTIME_DIR);
+ for (final File file : dataDirectory.listFiles()) {
+ file.delete();
+ }
+ dataDirectory.mkdirs();
+ InserterBabuDB inserter;
+ try {
+ final BabudbDataManager babudbDataManager=new BabudbDataManager((new File(dataDirectory,"banana.data")).getAbsolutePath());
+ inserter = new InserterBabuDB(babudbDataManager);
+ inserter.run(NUMBER_OF_ITEM);
+ inserter.close();
+ } catch (final Throwable throwable) {// NOPMD catch all
+ LOGGER.fatal("error", throwable);
+ }
+ }
+}
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java 2012-04-09 05:41:25 UTC (rev 2999)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java 2012-04-10 01:24:27 UTC (rev 3000)
@@ -57,8 +57,8 @@
dataDirectory.mkdirs();
InserterJdbm inserter;
try {
- final JdbmDataManager bananaDataManager=new JdbmDataManager((new File(dataDirectory,"banana.data")).getAbsolutePath());
- inserter = new InserterJdbm(bananaDataManager);
+ final JdbmDataManager jdbmDataManager=new JdbmDataManager((new File(dataDirectory,"banana.data")).getAbsolutePath());
+ inserter = new InserterJdbm(jdbmDataManager);
inserter.run(NUMBER_OF_ITEM);
inserter.close();
} catch (final Throwable throwable) {// NOPMD catch all
Added: trunk/joafip-4test/src/main/resources/log4j.properties
===================================================================
--- trunk/joafip-4test/src/main/resources/log4j.properties (rev 0)
+++ trunk/joafip-4test/src/main/resources/log4j.properties 2012-04-10 01:24:27 UTC (rev 3000)
@@ -0,0 +1,148 @@
+
+
+log4j.rootLogger=WARN,CONSOLE,FILE
+
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.Target=System.out
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+#log4j.appender.CONSOLE.layout.conversionPattern=[%p,%c{1},%t] %m%n
+#log4j.appender.CONSOLE.layout.ConversionPattern=[%5p] - %d [%t] %c (%F:%M:%L) %n %m%n%n
+log4j.appender.CONSOLE.layout.ConversionPattern=[%5p] - %d [%t] (%c.java:%M:%L) %n %m%n%n
+
+log4j.appender.FILE=org.apache.log4j.RollingFileAppender
+#log4j.appender.FILE.File=${webapp.root}/WEB-INF/log4j.log
+log4j.appender.FILE.File=logs/joafip.log
+log4j.appender.FILE.MaxFileSize=1024KB
+log4j.appender.FILE.MaxBackupIndex=3
+log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
+#log4j.appender.FILE.layout.conversionPattern=%d{ABSOLUTE} %5p %c{1},%t:%L - %m%n
+log4j.appender.FILE.layout.ConversionPattern=[%5p] - %d [%t] (%c.java:%M:%L) %n %m%n%n
+
+log4j.logger.net.sf.joafip=warn
+log4j.logger.net.sf.joafip.HelperMemoryUse=info
+log4j.logger.net.sf.joafip.meminspector=warn
+log4j.logger.net.sf.joafip.java.util=warn
+
+#log4j.logger.net.sf.joafip.btree=debug
+
+#log4j.logger.net.sf.joafip.file.service.RandomAccessFileReadWriteCache=debug
+#log4j.logger.net.sf.joafip.file.service.RandomAccessFileDirectNio=debug
+
+#log4j.logger.net.sf.joafip.heapfile.record.service=debug
+#log4j.logger.net.sf.joafip.heapfile.record.service.HeapElementManager=debug
+#log4j.logger.HeapElementManager=debug
+
+#log4j.logger.net.sf.joafip.heapfile.service.HeapFileDataManager=debug
+
+#log4j.logger.HeapFileDataManager=debug
+#log4j.logger.net.sf.joafip.heapfile.service.HeapMemoryDataManagerMock=debug
+
+#log4j.logger.net.sf.joafip.store.entity.objectio.ObjectStateMap=debug
+
+#log4j.logger.net.sf.joafip.store.entity.saver.StoreSaverSession=debug
+#log4j.logger.net.sf.joafip.store.entity.conversion.ReplacementDefSet=debug
+#log4j.logger.net.sf.joafip.store.entity.conversion.ReplacementDefMap=debug
+#log4j.logger.net.sf.joafip.store.service.garbage.LinkManager=debug
+#log4j.logger.net.sf.joafip.store.service.garbage.recordmgr.LinkRecordManager=debug
+#log4j.logger.net.sf.joafip.store.service.garbage.GarbageRecordManager=debug
+#log4j.logger.net.sf.joafip.store.service.garbage.GarbageManager=debug
+#log4j.logger.net.sf.joafip.store.service.garbage.StoreGarbager=debug
+#log4j.logger.net.sf.joafip.store.service.garbage.AttachedToRootSupport=debug
+#log4j.logger.net.sf.joafip.store.service.garbage.GarbageManager=debug
+#log4j.logger.net.sf.joafip.store.service.garbage=debug
+#log4j.logger.net.sf.joafip.store.service.garbage.rbt.ToGarbageRBTNodeManager=debug
+#log4j.logger.net.sf.joafip.store.service.Store=debug
+#log4j.logger.net.sf.joafip.store.service.StoreRemover=debug
+#log4j.logger.net.sf.joafip.store.service.saver.StoreSaver3=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.manager.ObjectIOManager=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.manager.ClassNameManager=debug
+#log4j.logger.net.sf.joafip.store.service.export_import.in.InObjectHandler=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOLazyGeneric=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOArray=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOBasic=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIODummy=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOEnum=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOImmediateExternalizable=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOImmediateGeneric=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOImmediateSerializable=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOInputStream=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOLazyExternalizable=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOLazyGeneric=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOLazySerializable=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOOutputStream=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOSerialize=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOSerializeGZipped=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOSerializeZipped=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ObjectIOString=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.ReferenceIO=debug
+#log4j.logger.net.sf.joafip.store.service.objectio.serialize.BasicOrReferenceIO=debug
+
+#log4j.logger.net.sf.joafip.store.service.heaprecordable.HeapRecordableManager=debug
+#log4j.logger.net.sf.joafip.store.service.objectfortest.Bob1=debug
+#log4j.logger.net.sf.joafip.store.service.proxy=debug
+#log4j.logger.net.sf.joafip.store.service.proxy.ClassEnhancer=debug
+#log4j.logger.net.sf.joafip.store.service.proxy.ProxyCallBack2=debug
+#log4j.logger.net.sf.joafip.store.service.export_import.in.XmlImporter=debug
+#log4j.logger.net.sf.joafip.store.service.conversion.ConversionManager=debug
+# set log4j.logger.net.sf.joafip.store.service.bytecode.ClassEnhancer=debug
+# -------- will output bytecode in runtime/class
+#log4j.logger.net.sf.joafip.store.service.bytecode.ClassEnhancer=debug
+
+#--- tests ---
+log4j.logger.net.sf.joafip.entity.BobForExport=debug
+#log4j.logger.net.sf.joafip.heapfile.record.service.TestHeapElementManager=debug
+#log4j.logger.net.sf.joafip.heapfile.service.TestHeapDataManager=debug
+#log4j.logger.net.sf.joafip.store.service.TestGarbage=debug
+#log4j.logger.net.sf.joafip.heapfile.record.service.TestHeapRecordManage=debug
+#log4j.logger.net.sf.joafip.service.changelog.CheckSaved=debug
+#log4j.logger.net.sf.joafip.service.bug.TestGarbageModeError=info
+#log4j.logger.net.sf.joafip.service.TestCrashSafe=debug
+#log4j.logger.net.sf.joafip.service.TestMultiAccessFilePersistence=debug
+#log4j.logger.net.sf.joafip.service.bug.savenum.TestEnumPersistence=debug
+#log4j.logger.net.sf.joafip.service.bug.savenum.TestEnumPersistenceMemory=debug
+log4j.logger.net.sf.joafip.service.rel400.TestHugeList=debug
+log4j.logger.net.sf.joafip.service.rel400.TestHugeListAutoSave=debug
+#log4j.logger.net.sf.joafip.service.rel400.MemoryEater=debug
+#log4j.logger.net.sf.joafip.store.service.TestGarbageForegroundFile=debug
+#log4j.logger.net.sf.joafip.store.service.TestGarbageForegroundMemory=debug
+#log4j.logger.net.sf.joafip.store.service.TestStoreWithBobFileLazy=debug
+#log4j.logger.net.sf.joafip.store.service.TestStoreWithBobFileDirect=debug
+#log4j.logger.net.sf.joafip.store.service.TestStoreWithBobFileLazyNoGarbage=debug
+#log4j.logger.net.sf.joafip.store.service.TestStoreWithBobMemoryDirect=debug
+#log4j.logger.net.sf.joafip.store.service.TestStoreWithBobMemoryLazy=debug
+#log4j.logger.net.sf.joafip.store.service.TestStoreSession=debug
+#log4j.logger.net.sf.joafip.service.TestVisitedModified=debug
+#log4j.logger.net.sf.joafip.store.service.TestStoreNoG=debug
+#log4j.logger.net.sf.joafip.store.service.TestStoreWithG=debug
+#log4j.logger.net.sf.joafip.ograph.ObjectGraphCreator=debug
+#log4j.logger.net.sf.joafip.store.service.classinfo.TestClassReplacement=debug
+#log4j.logger.net.sf.joafip.store.service.TestLinkManagementInMemory=debug
+#log4j.logger.net.sf.joafip.heapfile.service.HeapMemoryDataManagerMock=debug
+#log4j.logger.net.sf.joafip.meminspector.MemInspectorTest=debug
+#log4j.logger.net.sf.joafip.file.service.RandomAccessFileReadWriteCacheTest=debug
+#log4j.logger.net.sf.joafip.store.service.TestVisitedModified=debug
+#log4j.logger.net.sf.joafip.ograph.OGraphTest=debug
+log4j.logger.net.sf.joafip.store.service.proxy.TestCheckMethodVisitor=debug
+#--- no auto tests ---
+#log4j.logger.net.sf.joafip.performance.service=debug
+#log4j.logger.net.sf.joafip.service.bug.emis.TestEmis=debug
+log4j.logger.net.sf.joafip.performance.items.service.Inserter=info
+log4j.logger.net.sf.joafip.performance.items.service.InserterBKM=info
+log4j.logger.net.sf.joafip.performance.items.service.Searcher=info
+log4j.logger.net.sf.joafip.performance.items.service.SearcherBKM=info
+log4j.logger.net.sf.joafip.performance.items.service.ImportSearcher=info
+log4j.logger.net.sf.joafip.service.MainCrash=info
+log4j.logger.net.sf.joafip.service.MainAfterCrash=info
+log4j.logger.net.sf.joafip.service.MainWarnDataRecord1=debug
+
+#--- java agent ---
+#log4j.logger.net.sf.joafip.store.service.bytecode.PersistableTransformer=debug
+#log4j.logger.net.sf.joafip.store.service.bytecode.PersistableCodeGenerator=debug
+#log4j.logger.net.sf.joafip.service.JoafipJavaAgent=debug
+log4j.logger.net.sf.joafip.store.service.bytecode.ClassVisitorForStorable=debug
+#--- sample ---
+log4j.logger.net.sf.joafip.database.MainDatabase=info
+#--- meminspector ---
+log4j.logger.net.sf.joafip.meminspector.entity.NodeForObject=warn
+log4j.logger.net.sf.joafip.meminspector.service.show.JTreeForNodeForObject=info
+
Added: trunk/joafip-4test/src/test/java/net/sf/joafip/logger/TestCreateLogger.java
===================================================================
--- trunk/joafip-4test/src/test/java/net/sf/joafip/logger/TestCreateLogger.java (rev 0)
+++ trunk/joafip-4test/src/test/java/net/sf/joafip/logger/TestCreateLogger.java 2012-04-10 01:24:27 UTC (rev 3000)
@@ -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.logger;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class TestCreateLogger extends TestCase {
+
+ public void test() {
+ final JoafipLogger logger=JoafipLogger.getLogger(TestCreateLogger.class);
+ logger.fatal("fatal error message");
+ assertTrue("logger must be set",logger.loggerIsSet());
+ }
+}
Modified: trunk/joafip-common/src/main/java/net/sf/joafip/logger/JoafipLogger.java
===================================================================
--- trunk/joafip-common/src/main/java/net/sf/joafip/logger/JoafipLogger.java 2012-04-09 05:41:25 UTC (rev 2999)
+++ trunk/joafip-common/src/main/java/net/sf/joafip/logger/JoafipLogger.java 2012-04-10 01:24:27 UTC (rev 3000)
@@ -101,6 +101,10 @@
this.infoEnabled = infoEnabled;
}
+ public boolean loggerIsSet() {
+ return !(loggerFactory instanceof DummyLoggerFactory);
+ }
+
public boolean isDebugEnabled() {
return debugEnabled;
}
Modified: trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java
===================================================================
--- trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java 2012-04-09 05:41:25 UTC (rev 2999)
+++ trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java 2012-04-10 01:24:27 UTC (rev 3000)
@@ -49,6 +49,8 @@
*/
private static final long serialVersionUID = 8469844004206234652L;
+ private static final String UNSUPPORTED = "unsupported";
+
private static final String UNKNOWN_NEXT_IDENTIFIER = "unknown next identifier";
private static final String ID_KEY = "idKey";
@@ -56,8 +58,6 @@
private static final JoafipLogger LOGGER = JoafipLogger
.getLogger(JdbmDataManager.class);
- private static final String UNSUPPORTED = "unsupported";
-
private final String storageFileName;
private RecordManager recordManager;
Modified: trunk/joafip-log4j/src/main/java/net/sf/joafip/logger/Log4jAdapter.java
===================================================================
--- trunk/joafip-log4j/src/main/java/net/sf/joafip/logger/Log4jAdapter.java 2012-04-09 05:41:25 UTC (rev 2999)
+++ trunk/joafip-log4j/src/main/java/net/sf/joafip/logger/Log4jAdapter.java 2012-04-10 01:24:27 UTC (rev 3000)
@@ -65,6 +65,7 @@
this.logger = logger;
}
+ @SuppressWarnings("PMD")
private void assertForcedLogMethodIsSet() {
if (forcedLogMethod == null) {
throw new RuntimeException(
@@ -80,13 +81,15 @@
@Override
public void debug(final Object message) {
// logger.debug(message);
- if (logger.getLoggerRepository().isDisabled(Level.DEBUG_INT))
+ if (logger.getLoggerRepository().isDisabled(Level.DEBUG_INT)) {
return;
+ }
if (Level.DEBUG.isGreaterOrEqual(logger.getEffectiveLevel())) {
forcedLog(FQCN, Level.DEBUG, message, null);
}
}
+ @SuppressWarnings("PMD")
private void forcedLog(final String fqcn, final Priority level,
final Object message, final Throwable throwable) {
assertForcedLogMethodIsSet();
@@ -104,10 +107,12 @@
@Override
public void debug(final Object message, final Throwable throwable) {
// logger.debug(message, throwable);
- if (logger.getLoggerRepository().isDisabled(Level.DEBUG_INT))
+ if (logger.getLoggerRepository().isDisabled(Level.DEBUG_INT)) {
return;
- if (Level.DEBUG.isGreaterOrEqual(logger.getEffectiveLevel()))
+ }
+ if (Level.DEBUG.isGreaterOrEqual(logger.getEffectiveLevel())) {
forcedLog(FQCN, Level.DEBUG, message, throwable);
+ }
}
@Override
Modified: trunk/joafip-log4j/src/test/java/net/sf/joafip/logger/TestCreateLogger.java
===================================================================
--- trunk/joafip-log4j/src/test/java/net/sf/joafip/logger/TestCreateLogger.java 2012-04-09 05:41:25 UTC (rev 2999)
+++ trunk/joafip-log4j/src/test/java/net/sf/joafip/logger/TestCreateLogger.java 2012-04-10 01:24:27 UTC (rev 3000)
@@ -33,7 +33,8 @@
public class TestCreateLogger extends TestCase {
public void test() {
- JoafipLogger logger=JoafipLogger.getLogger(TestCreateLogger.class);
+ final JoafipLogger logger=JoafipLogger.getLogger(TestCreateLogger.class);
logger.fatal("fatal error message");
+ assertTrue("logger must be set",logger.loggerIsSet());
}
}
Modified: trunk/joafip-parent/pom.xml
===================================================================
--- trunk/joafip-parent/pom.xml 2012-04-09 05:41:25 UTC (rev 2999)
+++ trunk/joafip-parent/pom.xml 2012-04-10 01:24:27 UTC (rev 3000)
@@ -351,6 +351,7 @@
<module>../joafip-kvstore</module>
<module>../joafip-heapfile</module>
<module>../joafip-jdbm</module>
+ <module>../joafip-babudb</module>
<module>../joafip-pmap</module>
<module>../joafip-callback</module>
<module>../joafip-java-agent</module>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-10 01:24:34
|
Revision: 3000
http://joafip.svn.sourceforge.net/joafip/?rev=3000&view=rev
Author: luc_peuvrier
Date: 2012-04-10 01:24:27 +0000 (Tue, 10 Apr 2012)
Log Message:
-----------
data manager using babudb library
Modified Paths:
--------------
trunk/joafip-4test/pom.xml
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java
trunk/joafip-common/src/main/java/net/sf/joafip/logger/JoafipLogger.java
trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java
trunk/joafip-log4j/src/main/java/net/sf/joafip/logger/Log4jAdapter.java
trunk/joafip-log4j/src/test/java/net/sf/joafip/logger/TestCreateLogger.java
trunk/joafip-parent/pom.xml
Added Paths:
-----------
trunk/joafip-4test/src/main/java/net/sf/joafip/logger/
trunk/joafip-4test/src/main/java/net/sf/joafip/logger/MainTestLogger.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterBabuDB.java
trunk/joafip-4test/src/main/resources/log4j.properties
trunk/joafip-4test/src/test/java/net/
trunk/joafip-4test/src/test/java/net/sf/
trunk/joafip-4test/src/test/java/net/sf/joafip/
trunk/joafip-4test/src/test/java/net/sf/joafip/logger/
trunk/joafip-4test/src/test/java/net/sf/joafip/logger/TestCreateLogger.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-11 03:54:22
|
Revision: 3004
http://joafip.svn.sourceforge.net/joafip/?rev=3004&view=rev
Author: luc_peuvrier
Date: 2012-04-11 03:54:16 +0000 (Wed, 11 Apr 2012)
Log Message:
-----------
changes for new babudb tests
Modified Paths:
--------------
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java
trunk/joafip-4test/src/main/resources/log4j.properties
trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java 2012-04-10 03:40:22 UTC (rev 3003)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java 2012-04-11 03:54:16 UTC (rev 3004)
@@ -255,7 +255,7 @@
if( file.isDirectory()) {
deleteDir(file);
} else {
- if( file.delete() ) {
+ if( !file.delete() ) {
throw new FilePersistenceException(FAILED_DELETE+file);
}
}
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java 2012-04-10 03:40:22 UTC (rev 3003)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java 2012-04-11 03:54:16 UTC (rev 3004)
@@ -39,7 +39,8 @@
private static final JoafipLogger LOGGER = JoafipLogger
.getLogger(InserterJdbm.class);
- public InserterJdbm(final IHeapDataManager dataManager) throws FilePersistenceException,
+ public InserterJdbm(final IHeapDataManager dataManager)
+ throws FilePersistenceException,
FilePersistenceInvalidClassException,
FilePersistenceNotSerializableException,
FilePersistenceClassNotFoundException,
@@ -49,15 +50,14 @@
}
public static void main(final String[] args) {
- /* remove existing data */
- final File dataDirectory = new File(RUNTIME_DIR);
- for (final File file : dataDirectory.listFiles()) {
- file.delete();
- }
- dataDirectory.mkdirs();
- InserterJdbm inserter;
try {
- final JdbmDataManager jdbmDataManager=new JdbmDataManager((new File(dataDirectory,"banana.data")).getAbsolutePath());
+ final File dataDirectory = new File(RUNTIME_DIR);
+ /* remove existing data */
+ initializeDirectory(RUNTIME_DIR);
+ dataDirectory.mkdirs();
+ InserterJdbm inserter;
+ final JdbmDataManager jdbmDataManager = new JdbmDataManager(
+ (new File(dataDirectory, "banana.data")).getAbsolutePath());
inserter = new InserterJdbm(jdbmDataManager);
inserter.run(NUMBER_OF_ITEM);
inserter.close();
Modified: trunk/joafip-4test/src/main/resources/log4j.properties
===================================================================
--- trunk/joafip-4test/src/main/resources/log4j.properties 2012-04-10 03:40:22 UTC (rev 3003)
+++ trunk/joafip-4test/src/main/resources/log4j.properties 2012-04-11 03:54:16 UTC (rev 3004)
@@ -128,6 +128,9 @@
#log4j.logger.net.sf.joafip.service.bug.emis.TestEmis=debug
log4j.logger.net.sf.joafip.performance.items.service.Inserter=info
log4j.logger.net.sf.joafip.performance.items.service.InserterBKM=info
+log4j.logger.net.sf.joafip.performance.items.service.InserterJdbm=info
+log4j.logger.net.sf.joafip.performance.items.service.InserterBabuDB=info
+
log4j.logger.net.sf.joafip.performance.items.service.Searcher=info
log4j.logger.net.sf.joafip.performance.items.service.SearcherBKM=info
log4j.logger.net.sf.joafip.performance.items.service.ImportSearcher=info
Modified: trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java
===================================================================
--- trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java 2012-04-10 03:40:22 UTC (rev 3003)
+++ trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java 2012-04-11 03:54:16 UTC (rev 3004)
@@ -86,6 +86,7 @@
public BabudbDataManager(final String storageFileName) {
super();
this.storageFileName = storageFileName;
+ //Logging.start(Logging.LEVEL_DEBUG);
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-11 03:54:22
|
Revision: 3004
http://joafip.svn.sourceforge.net/joafip/?rev=3004&view=rev
Author: luc_peuvrier
Date: 2012-04-11 03:54:16 +0000 (Wed, 11 Apr 2012)
Log Message:
-----------
changes for new babudb tests
Modified Paths:
--------------
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/AbstractPerfService.java
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/InserterJdbm.java
trunk/joafip-4test/src/main/resources/log4j.properties
trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-14 07:40:00
|
Revision: 3005
http://joafip.svn.sourceforge.net/joafip/?rev=3005&view=rev
Author: luc_peuvrier
Date: 2012-04-14 07:39:53 +0000 (Sat, 14 Apr 2012)
Log Message:
-----------
changes for new test with jdbm
Modified Paths:
--------------
trunk/joafip-4test/src/main/resources/log4j.properties
trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java
trunk/joafip-jdbm/.project
trunk/joafip-jdbm/pom.xml
trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java
trunk/joafip-kvstore/.project
Added Paths:
-----------
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java
trunk/joafip-jdbm/doc/
trunk/joafip-jdbm/doc/jdbm2/
trunk/joafip-jdbm/doc/jdbm2/JdbmDataManager.java
trunk/joafip-log4j/target/classes/joafip_logger.properties
trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-sources.jar
trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-test-sources.jar
trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-tests.jar
trunk/joafip-log4j/target/joafip-log4j-4.0.0b8.jar
trunk/joafip-log4j/target/maven-archiver/
trunk/joafip-log4j/target/maven-archiver/pom.properties
trunk/joafip-log4j/target/surefire/
Added: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java 2012-04-14 07:39:53 UTC (rev 3005)
@@ -0,0 +1,63 @@
+/*
+ * 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.performance.items.service;
+
+import java.io.File;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.StorableAccess;
+import net.sf.joafip.jdbm.service.JdbmDataManager;
+import net.sf.joafip.kvstore.service.IHeapDataManager;
+import net.sf.joafip.logger.JoafipLogger;
+import net.sf.joafip.service.FilePersistenceClassNotFoundException;
+import net.sf.joafip.service.FilePersistenceDataCorruptedException;
+import net.sf.joafip.service.FilePersistenceException;
+import net.sf.joafip.service.FilePersistenceInvalidClassException;
+import net.sf.joafip.service.FilePersistenceNotSerializableException;
+import net.sf.joafip.service.FilePersistenceTooBigForSerializationException;
+
+@NotStorableClass
+@StorableAccess
+public class SearcherJdbm extends AbstractSearcher {
+
+ private static final JoafipLogger LOGGER = JoafipLogger
+ .getLogger(SearcherJdbm.class);
+
+
+ public SearcherJdbm(final IHeapDataManager dataManager)
+ throws FilePersistenceInvalidClassException,
+ FilePersistenceNotSerializableException,
+ FilePersistenceClassNotFoundException,
+ FilePersistenceDataCorruptedException, FilePersistenceException,
+ FilePersistenceTooBigForSerializationException {
+ super(dataManager);
+ }
+
+
+ public static void main(final String[] args) {
+ SearcherJdbm searcher;
+ try {
+ final File dataDirectory = new File(RUNTIME_DIR);
+ final JdbmDataManager jdbmDataManager = new JdbmDataManager(
+ (new File(dataDirectory, "banana.data")).getAbsolutePath());
+ searcher = new SearcherJdbm(jdbmDataManager);
+ searcher.run();
+ } catch (final Throwable throwable) {// NOPMD catch all
+ LOGGER.fatal("error", throwable);
+ }
+ }
+}
Modified: trunk/joafip-4test/src/main/resources/log4j.properties
===================================================================
--- trunk/joafip-4test/src/main/resources/log4j.properties 2012-04-11 03:54:16 UTC (rev 3004)
+++ trunk/joafip-4test/src/main/resources/log4j.properties 2012-04-14 07:39:53 UTC (rev 3005)
@@ -133,6 +133,7 @@
log4j.logger.net.sf.joafip.performance.items.service.Searcher=info
log4j.logger.net.sf.joafip.performance.items.service.SearcherBKM=info
+log4j.logger.net.sf.joafip.performance.items.service.SearcherJdbm=info
log4j.logger.net.sf.joafip.performance.items.service.ImportSearcher=info
log4j.logger.net.sf.joafip.service.MainCrash=info
log4j.logger.net.sf.joafip.service.MainAfterCrash=info
Modified: trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java
===================================================================
--- trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java 2012-04-11 03:54:16 UTC (rev 3004)
+++ trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java 2012-04-14 07:39:53 UTC (rev 3005)
@@ -270,10 +270,11 @@
try {
// deleted if exist in database or in pending modification map
boolean deleted;
+ final long id = dataRecordIdentifier.value;
byte[] bytes = database.lookup(1,
- longToBytes(dataRecordIdentifier.value), null).get();
+ longToBytes(id), null).get();
deleted = bytes != null;
- deleted |= dataMap.put(dataRecordIdentifier.value, null) != null;
+ deleted |= dataMap.put(id, null) != null;
return deleted;
} catch (Exception exception) {
throw new HeapException(exception);
@@ -289,10 +290,11 @@
* first search in pending modification map, and then if not in
* pending modification map search in database
*/
- byte[] data = dataMap.get(dataRecordIdentifier.value);
+ final long id = dataRecordIdentifier.value;
+ byte[] data = dataMap.get(id);
if (data == null) {
data = database.lookup(1,
- longToBytes(dataRecordIdentifier.value), null).get();
+ longToBytes(id), null).get();
}
return data;
} catch (Exception exception) {
@@ -306,7 +308,7 @@
throws HeapException {
try {
// created if not exist in database nor in pending modification map
- boolean created = !dataMap.containsKey(dataRecordIdentifier.value)
+ final boolean created = !dataMap.containsKey(dataRecordIdentifier.value)
&& database.lookup(1,
longToBytes(dataRecordIdentifier.value), null)
.get() != null;
Modified: trunk/joafip-jdbm/.project
===================================================================
--- trunk/joafip-jdbm/.project 2012-04-11 03:54:16 UTC (rev 3004)
+++ trunk/joafip-jdbm/.project 2012-04-14 07:39:53 UTC (rev 3005)
@@ -11,12 +11,12 @@
</arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
+ <name>net.sourceforge.pmd.eclipse.plugin.pmdBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
- <name>net.sourceforge.pmd.eclipse.plugin.pmdBuilder</name>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
Added: trunk/joafip-jdbm/doc/jdbm2/JdbmDataManager.java
===================================================================
--- trunk/joafip-jdbm/doc/jdbm2/JdbmDataManager.java (rev 0)
+++ trunk/joafip-jdbm/doc/jdbm2/JdbmDataManager.java 2012-04-14 07:39:53 UTC (rev 3005)
@@ -0,0 +1,289 @@
+/*
+ * 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.jdbm.service;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Set;
+
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
+import net.sf.joafip.kvstore.service.AbstractHeapDataManager;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.logger.JoafipLogger;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class JdbmDataManager extends AbstractHeapDataManager {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8469844004206234652L;
+
+ private static final String UNSUPPORTED = "unsupported";
+
+ private static final String UNKNOWN_NEXT_IDENTIFIER = "unknown next identifier";
+
+ private static final String ID_KEY = "idKey";
+
+ private static final JoafipLogger LOGGER = JoafipLogger
+ .getLogger(JdbmDataManager.class);
+
+ private final String storageFileName;
+
+ private RecordManager recordManager;
+
+ //private PrimaryTreeMap<Long, byte[]> dataMap;
+ private PrimaryHashMap<Long, byte[]> dataMap;
+
+ //private PrimaryTreeMap<String, Long> idMap;
+ private PrimaryHashMap<String, Long> idMap;
+
+ public JdbmDataManager(final String storageFileName) {
+ super();
+ this.storageFileName = storageFileName;
+ }
+
+ @Override
+ public boolean isDataLost() {
+ // can not check
+ return false;
+ }
+
+ @Override
+ public String getStorageFileName() throws HeapException {
+ return storageFileName;
+ }
+
+ @Override
+ public String getBackupFileName() throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ public String getChangeFileName() throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ protected void removeFiles() throws HeapException {
+ (new File(storageFileName)).delete();
+ }
+
+ @Override
+ protected void startServiceImpl(final boolean removeFiles) throws HeapException {
+ try {
+ if( removeFiles ) {
+ removeFiles();
+ }
+ recordManager = RecordManagerFactory
+ .createRecordManager(storageFileName);
+ //dataMap = recordManager.treeMap("record");
+ dataMap = recordManager.hashMap("record");
+ //idMap= recordManager.treeMap("id");
+ idMap= recordManager.hashMap("id");
+ final Long nextId=idMap.get(ID_KEY);
+ if( nextId==null) {
+ idMap.put(ID_KEY,0L);
+ recordManager.commit();
+ }
+ } catch (Exception exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ @Override
+ protected void stopServiceImpl() throws HeapException {
+ try {
+ recordManager.rollback();
+ recordManager.close();
+ } catch (Exception exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ @Override
+ protected void closeHeapManagerAfterException() {
+ try {
+ recordManager.rollback();
+ } catch (Exception exception) {
+ LOGGER.warn("roll backing after error", exception);
+ }
+ try {
+ recordManager.close();
+ } catch (Exception exception) {
+ LOGGER.warn("closing after error", exception);
+ }
+ }
+
+ @Override
+ protected void clearImpl() throws HeapException {
+ try {
+ dataMap.clear();
+ recordManager.commit();
+ } catch (Exception exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ @Override
+ protected void flushImp() throws HeapException {
+ try {
+ recordManager.commit();
+ } catch (Exception exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ @Override
+ protected void clearStandbyModificationImpl() throws HeapException {
+ try {
+ recordManager.rollback();
+ } catch (Exception exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ @Override
+ protected DataRecordIdentifier getNextFreeDataRecordIdentifierImpl()
+ throws HeapException {
+ final Long nextId=idMap.get(ID_KEY);
+ if( nextId==null) {
+ throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
+ }
+ return new DataRecordIdentifier(nextId.longValue());
+ }
+
+ @Override
+ protected void setNextFreeDataRecordIdentifierImpl(
+ final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ idMap.put(ID_KEY, dataRecordIdentifier.value);
+ }
+
+ @Override
+ protected DataRecordIdentifier getNewDataRecordIdentifierImpl()
+ throws HeapException {
+ final Long nextId=idMap.get(ID_KEY);
+ if( nextId==null) {
+ throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
+ }
+ final long longValue = nextId.longValue();
+ idMap.put(ID_KEY, longValue+1);
+ return new DataRecordIdentifier(longValue);
+ }
+
+ @Override
+ protected boolean deleteDataRecordImpl(
+ final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ return dataMap.remove(dataRecordIdentifier.value)!=null;
+ }
+
+ @Override
+ protected byte[] readDataRecordImpl(
+ final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ return dataMap.get(dataRecordIdentifier.value);
+ }
+
+ @Override
+ protected boolean writeDataRecordImpl(
+ final DataRecordIdentifier dataRecordIdentifier,final byte[] data)
+ throws HeapException {
+ return dataMap.put(dataRecordIdentifier.value,data)==null;
+ }
+
+ @Override
+ protected boolean hasDataRecordImpl(
+ final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ return dataMap.containsKey(dataRecordIdentifier.value);
+ }
+
+ @Override
+ protected int getNumberOfDataRecordImpl() throws HeapException {
+ return dataMap.size();
+ }
+
+ @Override
+ protected int getNumberOfFreeRecordImpl() throws HeapException {
+ return 0;
+ }
+
+ @Override
+ protected long heapSizeImpl() throws HeapException {
+ return 0;
+ }
+
+ @Override
+ protected long freeSizeImpl() throws HeapException {
+ return 0;
+ }
+
+ @Override
+ protected long usedSizeImpl() throws HeapException {
+ return 0;
+ }
+
+ @Override
+ protected DataRecordIdentifier removeFirstDataRecordImpl()
+ throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ public void backup(final long identifier,final int maxBackup) throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ protected Set<DataRecordIdentifier> getDataRecordIdentifierSetImpl()
+ throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ protected Iterator<DataRecordIdentifier> dataRecordIteratorImpl()
+ throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ public long getRecordPositionInfile(final DataRecordIdentifier identifier)
+ throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ public long getLastRecordPositionInFile() throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ public void setDataRecordKeyComparator(
+ final IDataRecordKeyManager dataRecordKeyComparator) throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+}
Modified: trunk/joafip-jdbm/pom.xml
===================================================================
--- trunk/joafip-jdbm/pom.xml 2012-04-11 03:54:16 UTC (rev 3004)
+++ trunk/joafip-jdbm/pom.xml 2012-04-14 07:39:53 UTC (rev 3005)
@@ -20,9 +20,9 @@
<dependencies>
<dependency>
- <groupId>jdbm</groupId>
- <artifactId>jdbm</artifactId>
- <version>2.4</version>
+ <groupId>JDBM</groupId>
+ <artifactId>JDBM</artifactId>
+ <version>3.0-SNAPSHOT</version>
</dependency>
<dependency>
Modified: trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java
===================================================================
--- trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java 2012-04-11 03:54:16 UTC (rev 3004)
+++ trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java 2012-04-14 07:39:53 UTC (rev 3005)
@@ -25,12 +25,13 @@
import java.io.File;
import java.util.Iterator;
+import java.util.Map;
+import java.util.NavigableMap;
import java.util.Set;
+import java.util.TreeMap;
-import jdbm.PrimaryTreeMap;
-import jdbm.RecordManager;
-import jdbm.RecordManagerFactory;
-
+import net.kotek.jdbm.DB;
+import net.kotek.jdbm.DBMaker;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.service.AbstractHeapDataManager;
@@ -49,23 +50,31 @@
*/
private static final long serialVersionUID = 8469844004206234652L;
+ private static final String ID_MAP_NAME = "id";
+
+ private static final String DATA_MAP_NAME = "record";
+
+ private static final String ID_KEY = "idKey";
+
private static final String UNSUPPORTED = "unsupported";
private static final String UNKNOWN_NEXT_IDENTIFIER = "unknown next identifier";
- private static final String ID_KEY = "idKey";
-
private static final JoafipLogger LOGGER = JoafipLogger
.getLogger(JdbmDataManager.class);
private final String storageFileName;
- private RecordManager recordManager;
+ private DB database;
- private PrimaryTreeMap<Long, byte[]> dataMap;
+ /** pending modification map */
+ private final Map<Long, byte[]> dataMap = new TreeMap<Long, byte[]>();
- private PrimaryTreeMap<String, Long> idMap;
+ /** next data record identifier value */
+ private long nextIdentifier;
+ private NavigableMap<Long, byte[]> persistentDataMap;
+
public JdbmDataManager(final String storageFileName) {
super();
this.storageFileName = storageFileName;
@@ -98,20 +107,39 @@
}
@Override
- protected void startServiceImpl(final boolean removeFiles) throws HeapException {
+ protected void startServiceImpl(final boolean removeFiles)
+ throws HeapException {
try {
- if( removeFiles ) {
+ if (removeFiles) {
removeFiles();
}
- recordManager = RecordManagerFactory
- .createRecordManager(storageFileName);
- dataMap = recordManager.treeMap("record");
- idMap= recordManager.treeMap("id");
- final Long nextId=idMap.get(ID_KEY);
- if( nextId==null) {
- idMap.put(ID_KEY,0L);
- recordManager.commit();
+
+ final DBMaker dbMaker = DBMaker.openFile(storageFileName);
+ dbMaker.disableTransactions();
+ dbMaker.enableHardCache();
+ // open existing database or create database
+ database = dbMaker.make();
+
+ // get or create the data record persisted map
+ persistentDataMap = database.getTreeMap(DATA_MAP_NAME);
+ if (persistentDataMap == null) {
+ persistentDataMap = database.createTreeMap(DATA_MAP_NAME);
}
+
+ // get or create the next data record identifier
+ NavigableMap<String, Long> persistenteIdMap = database
+ .getTreeMap(ID_MAP_NAME);
+ if (persistenteIdMap == null) {
+ persistenteIdMap = database.createTreeMap(ID_MAP_NAME);
+ }
+ final Long nextId = persistenteIdMap.get(ID_KEY);
+ if (nextId == null) {
+ persistenteIdMap.put(ID_KEY, 0L);
+ database.commit();
+ nextIdentifier = 0L;
+ } else {
+ nextIdentifier = nextId.longValue();
+ }
} catch (Exception exception) {
throw new HeapException(exception);
}
@@ -120,8 +148,14 @@
@Override
protected void stopServiceImpl() throws HeapException {
try {
- recordManager.rollback();
- recordManager.close();
+ // discard pending change
+ dataMap.clear();
+ // the data record persisted map should not be modified : is commit
+ // needed ?
+ database.commit();
+ database.clearCache();
+ persistentDataMap = null;// NOPMD
+ database.close();
} catch (Exception exception) {
throw new HeapException(exception);
}
@@ -129,13 +163,16 @@
@Override
protected void closeHeapManagerAfterException() {
+ dataMap.clear();
try {
- recordManager.rollback();
- } catch (Exception exception) {
- LOGGER.warn("roll backing after error", exception);
+ database.commit();
+ } catch (Throwable throwable) {
+ LOGGER.warn("roll backing after error", throwable);
}
+ database.clearCache();
+ persistentDataMap = null;// NOPMD
try {
- recordManager.close();
+ database.close();
} catch (Exception exception) {
LOGGER.warn("closing after error", exception);
}
@@ -144,8 +181,15 @@
@Override
protected void clearImpl() throws HeapException {
try {
+ // discard pending change
dataMap.clear();
- recordManager.commit();
+ // clear all
+ persistentDataMap.clear();
+ // commit the clearing
+ database.commit();
+ database.clearCache();
+ // fresh instance
+ persistentDataMap = database.getTreeMap(DATA_MAP_NAME);
} catch (Exception exception) {
throw new HeapException(exception);
}
@@ -154,7 +198,30 @@
@Override
protected void flushImp() throws HeapException {
try {
- recordManager.commit();
+ // pending modification to persistent map
+ for (Map.Entry<Long, byte[]> entry : dataMap.entrySet()) {
+ final Long id = entry.getKey();
+ final byte[] value = entry.getValue();
+ if (value == null) {
+ persistentDataMap.remove(id);
+ } else {
+ persistentDataMap.put(id, value);
+ }
+ }
+ dataMap.clear();
+
+ // update next data record identifier
+ final NavigableMap<String, Long> persistenteIdMap = database
+ .getTreeMap(ID_MAP_NAME);
+ if (persistenteIdMap == null) {
+ throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
+ }
+ persistenteIdMap.put(ID_KEY, nextIdentifier);
+ // commit the changes
+ database.commit();
+ database.clearCache();
+ // fresh instance
+ persistentDataMap = database.getTreeMap(DATA_MAP_NAME);
} catch (Exception exception) {
throw new HeapException(exception);
}
@@ -163,7 +230,25 @@
@Override
protected void clearStandbyModificationImpl() throws HeapException {
try {
- recordManager.rollback();
+ // discard pending change
+ dataMap.clear();
+ // restore previous next data record identifier
+ final NavigableMap<String, Long> persistenteIdMap = database
+ .getTreeMap(ID_MAP_NAME);
+ if (persistenteIdMap == null) {
+ throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
+ }
+ final Long nextId = persistenteIdMap.get(ID_KEY);
+ if (nextId == null) {
+ throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
+ }
+ nextIdentifier = nextId.longValue();
+ // the data record persisted map should not be modified : is commit
+ // needed ?
+ database.commit();
+ database.clearCache();
+ // fresh instance
+ persistentDataMap = database.getTreeMap(DATA_MAP_NAME);
} catch (Exception exception) {
throw new HeapException(exception);
}
@@ -172,59 +257,67 @@
@Override
protected DataRecordIdentifier getNextFreeDataRecordIdentifierImpl()
throws HeapException {
- final Long nextId=idMap.get(ID_KEY);
- if( nextId==null) {
- throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
- }
- return new DataRecordIdentifier(nextId.longValue());
+ return new DataRecordIdentifier(nextIdentifier);
}
@Override
protected void setNextFreeDataRecordIdentifierImpl(
- final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
- idMap.put(ID_KEY, dataRecordIdentifier.value);
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ nextIdentifier = dataRecordIdentifier.value;
}
@Override
protected DataRecordIdentifier getNewDataRecordIdentifierImpl()
throws HeapException {
- final Long nextId=idMap.get(ID_KEY);
- if( nextId==null) {
- throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
- }
- final long longValue = nextId.longValue();
- idMap.put(ID_KEY, longValue+1);
- return new DataRecordIdentifier(longValue);
+ return new DataRecordIdentifier(nextIdentifier++);
}
@Override
protected boolean deleteDataRecordImpl(
- final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
- return dataMap.remove(dataRecordIdentifier.value)!=null;
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ boolean deleted;
+ final long id = dataRecordIdentifier.value;
+ deleted = dataMap.put(dataRecordIdentifier.value, null) != null
+ || persistentDataMap.containsKey(id);
+ return deleted;
}
@Override
protected byte[] readDataRecordImpl(
- final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
- return dataMap.get(dataRecordIdentifier.value);
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ final long id = dataRecordIdentifier.value;
+ byte[] data = dataMap.get(id);
+ if (data == null) {
+ data = persistentDataMap.get(id);
+ }
+ return data;
}
@Override
protected boolean writeDataRecordImpl(
- final DataRecordIdentifier dataRecordIdentifier,final byte[] data)
+ final DataRecordIdentifier dataRecordIdentifier, final byte[] data)
throws HeapException {
- return dataMap.put(dataRecordIdentifier.value,data)==null;
+ final long id = dataRecordIdentifier.value;
+ final boolean created = !dataMap.containsKey(id)
+ && !persistentDataMap.containsKey(id);
+ dataMap.put(id, data);
+ return created;
}
@Override
protected boolean hasDataRecordImpl(
- final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
- return dataMap.containsKey(dataRecordIdentifier.value);
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ final long id = dataRecordIdentifier.value;
+ return dataMap.containsKey(id) || persistentDataMap.containsKey(id);
}
@Override
protected int getNumberOfDataRecordImpl() throws HeapException {
- return dataMap.size();
+ return persistentDataMap.size();
}
@Override
@@ -254,7 +347,8 @@
}
@Override
- public void backup(final long identifier,final int maxBackup) throws HeapException {
+ public void backup(final long identifier, final int maxBackup)
+ throws HeapException {
throw new HeapException(UNSUPPORTED);
}
@@ -283,7 +377,8 @@
@Override
public void setDataRecordKeyComparator(
- final IDataRecordKeyManager dataRecordKeyComparator) throws HeapException {
+ final IDataRecordKeyManager dataRecordKeyComparator)
+ throws HeapException {
throw new HeapException(UNSUPPORTED);
}
}
Modified: trunk/joafip-kvstore/.project
===================================================================
--- trunk/joafip-kvstore/.project 2012-04-11 03:54:16 UTC (rev 3004)
+++ trunk/joafip-kvstore/.project 2012-04-14 07:39:53 UTC (rev 3005)
@@ -11,12 +11,12 @@
</arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
+ <name>net.sourceforge.pmd.eclipse.plugin.pmdBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
- <name>net.sourceforge.pmd.eclipse.plugin.pmdBuilder</name>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
Added: trunk/joafip-log4j/target/classes/joafip_logger.properties
===================================================================
--- trunk/joafip-log4j/target/classes/joafip_logger.properties (rev 0)
+++ trunk/joafip-log4j/target/classes/joafip_logger.properties 2012-04-14 07:39:53 UTC (rev 3005)
@@ -0,0 +1 @@
+net.sf.joafip.logger.IJoafipLoggerFactory=net.sf.joafip.logger.Log4JFactory
\ No newline at end of file
Added: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-sources.jar
===================================================================
(Binary files differ)
Property changes on: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-sources.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-test-sources.jar
===================================================================
(Binary files differ)
Property changes on: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-test-sources.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-tests.jar
===================================================================
(Binary files differ)
Property changes on: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-tests.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8.jar
===================================================================
(Binary files differ)
Property changes on: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/joafip-log4j/target/maven-archiver/pom.properties
===================================================================
--- trunk/joafip-log4j/target/maven-archiver/pom.properties (rev 0)
+++ trunk/joafip-log4j/target/maven-archiver/pom.properties 2012-04-14 07:39:53 UTC (rev 3005)
@@ -0,0 +1,5 @@
+#Generated by Maven
+#Mon Jan 02 05:20:46 CET 2012
+version=4.0.0b8
+groupId=net.sf.joafip
+artifactId=joafip-log4j
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-14 07:40:00
|
Revision: 3005
http://joafip.svn.sourceforge.net/joafip/?rev=3005&view=rev
Author: luc_peuvrier
Date: 2012-04-14 07:39:53 +0000 (Sat, 14 Apr 2012)
Log Message:
-----------
changes for new test with jdbm
Modified Paths:
--------------
trunk/joafip-4test/src/main/resources/log4j.properties
trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java
trunk/joafip-jdbm/.project
trunk/joafip-jdbm/pom.xml
trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java
trunk/joafip-kvstore/.project
Added Paths:
-----------
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java
trunk/joafip-jdbm/doc/
trunk/joafip-jdbm/doc/jdbm2/
trunk/joafip-jdbm/doc/jdbm2/JdbmDataManager.java
trunk/joafip-log4j/target/classes/joafip_logger.properties
trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-sources.jar
trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-test-sources.jar
trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-tests.jar
trunk/joafip-log4j/target/joafip-log4j-4.0.0b8.jar
trunk/joafip-log4j/target/maven-archiver/
trunk/joafip-log4j/target/maven-archiver/pom.properties
trunk/joafip-log4j/target/surefire/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-17 05:05:59
|
Revision: 3012
http://joafip.svn.sourceforge.net/joafip/?rev=3012&view=rev
Author: luc_peuvrier
Date: 2012-04-17 05:05:53 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
for for storable management moved to joafip-kvstore project
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.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/entity/TestAbstractFileStorable.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
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/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
Added Paths:
-----------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/ToBackupRecord.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/FileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IFileForStorable.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/AbstractFileStorable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/IFileStorable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/ToBackupRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/IFileForStorable.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-17 06:45:06
|
Revision: 3013
http://joafip.svn.sourceforge.net/joafip/?rev=3013&view=rev
Author: luc_peuvrier
Date: 2012-04-17 06:44:59 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
for tests some moves from joafip-heapfile to joafip-kvstore and joafip-file
Modified Paths:
--------------
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java
trunk/joafip-file/src/test/java/net/sf/joafip/file/entity/FileAccessRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.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/TestHeapElementManager.java
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/TestStoreRestore.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java
trunk/joafip-testsuite/pom.xml
trunk/joafip-testsuite/src/main/java/net/sf/joafip/PersistanceTestsNoLongTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/file/FileTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/RecordTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/entity/RecordEntityTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/service/RecordServiceTests.java
Added Paths:
-----------
trunk/joafip-file/src/test/java/net/sf/joafip/file/service/TestRandomAccessFileCache.java
trunk/joafip-kvstore/src/test/java/net/
trunk/joafip-kvstore/src/test/java/net/sf/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/file/service/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/KeyValueStoreTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/entity/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/KVRecordTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/service/
Removed Paths:
-------------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestRandomAccessFileCache.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-17 05:06:03
|
Revision: 3012
http://joafip.svn.sourceforge.net/joafip/?rev=3012&view=rev
Author: luc_peuvrier
Date: 2012-04-17 05:05:53 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
for for storable management moved to joafip-kvstore project
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.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/entity/TestAbstractFileStorable.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
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/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
Added Paths:
-----------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/ToBackupRecord.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/FileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IFileForStorable.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/AbstractFileStorable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/IFileStorable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/ToBackupRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/IFileForStorable.java
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/AbstractFileStorable.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/AbstractFileStorable.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/AbstractFileStorable.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -1,424 +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.entity;
-
-import java.util.Arrays;
-
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.service.FileForStorable;
-import net.sf.joafip.heapfile.service.IFileForStorable;
-import net.sf.joafip.kvstore.entity.EnumFileState;
-import net.sf.joafip.kvstore.service.HeapException;
-import net.sf.joafip.logger.JoafipLogger;
-
-/**
- * all that is common to storable in file using {@link FileForStorable}:<br>
- * <ul>
- * <li>the {@link FileForStorable} manager to use</li>
- * <li>position of data in file</li>
- * <li>flags for first creation and state change</li>
- * <li>primitive type read and write in file</li>
- * <li>crc32 compute and check for data integrity check</li>
- * </ul>
- *
- * by extension make able to create mutable or immutable object, immutable are
- * for file record unique representation, mutable make able to change the file
- * record represented<br>
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public abstract class AbstractFileStorable implements IFileStorable {
-
- protected final JoafipLogger logger = JoafipLogger.getLogger(getClass());// NOPMD
-
- private static final String ALREADY_READ = "already read";
-
- private static final String RECORD_INTEGRITY_ERROR = "record integrity error";
-
- private static final String NO_VALUE_CHANGE_TO_WRITE = "no value change to write";
-
- private static final String READING_ERASE_VALUE_CHANGE = "reading erase value change";
-
- /** position in file of this in marshallized forms */
- protected final long positionInFile;
-
- /** to read/write this in file */
- protected final IFileForStorable fileForStorable;
-
- /** to compute crc32 record header */
- private transient int crc32;
-
- /** current number of byte read or wrote */
- private transient int numberOfByteReadWrote = 0;
-
- /** input output buffer */
- private transient byte[] ioBuffer;
-
- private transient int readInIoBuffer;
-
- /**
- * true if this value changed, creation implies no value to save since not
- * read and not write
- */
- protected boolean valueChangedToSave = false;
-
- /** true if just created in memory, never read from file */
- protected boolean justCreated = true;
-
- /**
- * @param fileForStorable
- * @param positionInFile
- */
- public AbstractFileStorable(final IFileForStorable fileForStorable,
- final long positionInFile) {
- super();
- this.fileForStorable = fileForStorable;
- this.positionInFile = positionInFile;
- }
-
- public void clear() {
- valueChangedToSave = false;
- justCreated = true;
- }
-
- public long getPositionInFile() {
- return positionInFile;
- }
-
- public void readFromFile() throws HeapException {
- // ASSERTX
- assert justCreated : ALREADY_READ;
- // ASSERTX
- assert !valueChangedToSave : READING_ERASE_VALUE_CHANGE;
- fileForStorable.seek(positionInFile);
- crc32 = 0;
- ioBuffer = null;// NOPMD
- unmarshallImpl();
- ioBuffer = null;// NOPMD
- justCreated = false;
- }
-
- public byte[] writeToFile() throws HeapException {
- // ASSERTX
- assert valueChangedToSave : NO_VALUE_CHANGE_TO_WRITE;
- fileForStorable.seek(positionInFile);
- crc32 = 0;
- numberOfByteReadWrote = 0;
- ioBuffer = new byte[toMarshallSize()];
- marshallImpl();
- fileForStorable.write(ioBuffer);
- valueChangedToSave = false;
- final byte[] result = ioBuffer;
- ioBuffer = null;// NOPMD discard
- return result;
- }
-
- /**
- *
- * @return number of byte to marshal
- * @throws HeapException
- */
- protected abstract int toMarshallSize() throws HeapException;
-
- /**
- * Unmarshalling implementation for read<br>
- * {@link #crc32} is set to zero<br>
- *
- * @throws HeapException
- */
- protected abstract void unmarshallImpl() throws HeapException;
-
- /**
- * marshaling implementation for write<br>
- * {@link #crc32} is set to zero<br>
- *
- * @throws HeapException
- */
- protected abstract void marshallImpl() throws HeapException;
-
- /**
- *
- * @return true if just created ( not read from file and not setted )
- */
- public boolean isJustCreated() {
- return justCreated;
- }
-
- /**
- * to know if the value state change
- *
- * @return true if value changed
- */
- public boolean isValueChangedToSave() {
- return valueChangedToSave;
- }
-
- /**
- * set this record have value changed, so to save
- *
- * @throws HeapException
- */
- public void setValueIsChangedValueToSave() throws HeapException {
- if (!valueChangedToSave) {
- valueChangedToSave = true;
- justCreated = false;
- valueChangedAction();
- }
- }
-
- protected abstract void valueChangedAction() throws HeapException;
-
- public void setValueIsNotChanged() {
- valueChangedToSave = false;
- }
-
- /**
- * update crc32 with byte value in buffer
- *
- * @param buffer
- * bytes for crc32 update
- */
- private void updateCrc32(final byte[] buffer) {
- updateCrc32(buffer, 0, buffer.length);
- }
-
- private void updateCrc32(final byte[] buffer, final int start,
- final int length) {
-
- for (int i = 0; i < length; i++) {
- final byte byteValue = buffer[start + i];
- updateCrc32(byteValue);
- }
-
- }
-
- private void updateCrc32(final byte byteValue) {
- for (int j = 0; j < 8; j++) {
- final int testbit = ((crc32 >> 31) & 1) ^ ((byteValue >> j) & 1);
- crc32 <<= 2;
- if (testbit != 0) {
- crc32 ^= 0x8005; /* 32 bit crc */
- }
- }
- }
-
- protected void clearCrc32() {
- crc32 = 0;
- }
-
- protected int getCrc32() {
- return crc32;
- }
-
- protected int readFileToIoBuffer(final int size) throws HeapException {
- ioBuffer = new byte[size];
- readInIoBuffer = fileForStorable.read(ioBuffer);
- numberOfByteReadWrote = 0;
- return readInIoBuffer;
- }
-
- /**
- * read extending ioBuffer
- *
- * @param newSize
- * ioBuffer new size
- * @throws HeapException
- */
- protected void readFileAppendToIoBuffer(final int newSize)
- throws HeapException {
- if (newSize > ioBuffer.length) {
- ioBuffer = Arrays.copyOf(ioBuffer, newSize);
- final int appendSize = newSize - readInIoBuffer;
- final byte[] tempBuffer = new byte[appendSize];
- // FIXMELUC _________________use of additional read
- // read(iobuffer,readInIoBuffer/*offset*/,appendSize/*length*/);
- fileForStorable.read(tempBuffer);
- System.arraycopy(tempBuffer, 0, ioBuffer, readInIoBuffer,
- appendSize);
- }
- }
-
- /**
- * read and check CRC32
- *
- * @throws HeapException
- * read error crc32 error in record
- */
- protected void readAndCheckCrc32() throws HeapException {
- final int computedCrc32 = crc32;
- final int readCrc32 = readInteger();
- if (computedCrc32 != readCrc32) {
- throw new HeapException(RECORD_INTEGRITY_ERROR
- + " record position=" + positionInFile + " read="
- + readCrc32 + " computed=" + computedCrc32 + " nb rd/wr="
- + numberOfByteReadWrote, EnumFileState.STATE_CORRUPTED);
- }
- }
-
- /**
- * read bytes
- *
- * @param length
- * number of bytes to read
- * @return the bytes read
- * @throws HeapException
- */
- protected byte[] readBytes(final int length) throws HeapException {
- final byte[] dataByteArray = new byte[length];
- System.arraycopy(ioBuffer, numberOfByteReadWrote, dataByteArray, 0,
- length);
- numberOfByteReadWrote += length;
- updateCrc32(dataByteArray);
- return dataByteArray;
- }
-
- /**
- * unmarshal from byte array current {@link #dataByteArrayIndex} index to
- * long<br>
- * {@link #dataByteArrayIndex} is updated to next data to read position<br>
- *
- * @param dataByteArray
- * @return the unmarshaled value
- * @throws HeapException
- */
- protected long readLong() throws HeapException {
- long value = 0;
- for (int byteIndex = 7; byteIndex >= 0; byteIndex--) {
- final byte byteValue = ioBuffer[numberOfByteReadWrote + byteIndex];
- value = (value << 8) | (((long) byteValue) & 0xff);
- }
- updateCrc32(ioBuffer, numberOfByteReadWrote, 8);
- numberOfByteReadWrote += 8;
- return value;
- }
-
- protected int readInteger() throws HeapException {
- int value = 0;
- for (int byteIndex = 3; byteIndex >= 0; byteIndex--) {
- final byte byteValue = ioBuffer[numberOfByteReadWrote + byteIndex];
- value = (value << 8) | (((int) byteValue) & 0xff);
- }
- updateCrc32(ioBuffer, numberOfByteReadWrote, 4);
- numberOfByteReadWrote += 4;
- return value;
- }
-
- protected boolean readBoolean() throws HeapException {
- final byte byteValue = ioBuffer[numberOfByteReadWrote++];
- updateCrc32(byteValue);
- return byteValue == 0 ? false : true;
- }
-
- protected byte readByte() throws HeapException {
- final byte byteValue = ioBuffer[numberOfByteReadWrote++];
- updateCrc32(byteValue);
- return byteValue;
- }
-
- /**
- * write bytes
- *
- * @param dataByteArray
- * bytes to write
- * @throws HeapException
- */
- protected void writeBytes(final byte[] dataByteArray) throws HeapException {
- System.arraycopy(dataByteArray, 0, ioBuffer, numberOfByteReadWrote,
- dataByteArray.length);
- numberOfByteReadWrote += dataByteArray.length;
- updateCrc32(dataByteArray);
- }
-
- /**
- * Marshal long value to byte array current {@link #dataByteArrayIndex}
- * index<br>
- * {@link #dataByteArrayIndex} is updated to next data to write position<br>
- *
- * @param value
- * the value to marshal
- * @throws HeapException
- */
- protected void writeLong(final long value) throws HeapException {
- long localValue = value;
- for (int byteIndex = 0; byteIndex < 8; byteIndex++) {
- updateCrc32(ioBuffer[numberOfByteReadWrote++] = (byte) localValue);
- localValue >>= 8;
- }
- }
-
- protected void writeInteger(final int value) throws HeapException {
- int localValue = value;
- for (int byteIndex = 0; byteIndex < 4; byteIndex++) {
- updateCrc32(ioBuffer[numberOfByteReadWrote++] = (byte) localValue);
- localValue >>= 8;
- }
- }
-
- protected void writeCrc32() throws HeapException {
- int localValue = crc32;
- for (int byteIndex = 0; byteIndex < 4; byteIndex++) {
- ioBuffer[numberOfByteReadWrote++] = (byte) localValue;
- localValue >>= 8;
- }
- }
-
- protected void writeBoolean(final boolean value) throws HeapException {
- updateCrc32(ioBuffer[numberOfByteReadWrote++] = (byte) (value ? 1 : 0));
- }
-
- protected void writeByte(final byte value) throws HeapException {
- updateCrc32(ioBuffer[numberOfByteReadWrote++] = value);
- }
-
- @Override
- public int hashCode() {
- return (int) (positionInFile ^ (positionInFile >>> 32));
- }
-
- @Override
- public boolean equals(final Object obj) {
- final boolean equals;
- if (obj == this) {
- equals = true;
- } else {
- assert obj != null : "do no accept null parameter";
- assert obj instanceof AbstractFileStorable : "must be instance of AbstractFileStorable";
- final AbstractFileStorable storable = (AbstractFileStorable) obj;
- equals = positionInFile == storable.positionInFile;
- }
- return equals;
- }
-
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("AbstractFileStorable ");
- builder.append(super.toString());
- builder.append(" [fileForStorable=");
- builder.append(fileForStorable);
- builder.append(", justCreated=");
- builder.append(justCreated);
- builder.append(", positionInFile=");
- builder.append(positionInFile);
- builder.append(", valueChangedToSave=");
- builder.append(valueChangedToSave);
- builder.append("]");
- return builder.toString();
- }
-}
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/IFileStorable.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/IFileStorable.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/IFileStorable.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -1,51 +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.entity;
-
-import net.sf.joafip.heapfile.service.FileForStorable;
-import net.sf.joafip.kvstore.service.HeapException;
-
-/**
- * class implementing this can be store in file using {@link FileForStorable}<br>
- *
- * @author luc peuvrier
- *
- */
-public interface IFileStorable {
-
- /**
- *
- * @return position in file of this file storable
- */
- long getPositionInFile();
-
- /**
- * write this file storable to file
- *
- * @return bytes wrote
- * @throws HeapException
- */
- byte[] writeToFile() throws HeapException;
-
- /**
- * read this file storable from file
- *
- * @throws HeapException
- */
- void readFromFile() throws HeapException;
-
-}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -17,8 +17,8 @@
package net.sf.joafip.heapfile.record.entity;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.entity.AbstractFileStorable;
import net.sf.joafip.heapfile.record.service.HeapElementManager;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -20,9 +20,9 @@
import net.sf.joafip.Fortest;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.entity.AbstractFileStorable;
import net.sf.joafip.heapfile.record.service.HeapElementManager;
import net.sf.joafip.heapfile.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.entity.IDataRecordKey;
import net.sf.joafip.kvstore.service.HeapException;
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/ToBackupRecord.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/ToBackupRecord.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/ToBackupRecord.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -1,84 +0,0 @@
-/*
- * Copyright 2008 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.entity;
-
-import net.sf.joafip.NotStorableClass;
-
-/**
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public class ToBackupRecord implements Comparable<ToBackupRecord> {
-
- private final long positionInFile;
-
- private final byte[] data;
-
- public ToBackupRecord(final long positionInFile, final byte[] data) {// NOPMD
- // expose
- // data
- super();
- this.positionInFile = positionInFile;
- this.data = data;
- }
-
- public byte[] getData() {
- return data;// NOPMD expose data
- }
-
- public long getPositionInFile() {
- return positionInFile;
- }
-
- public int compareTo(final ToBackupRecord other) {
- final int compareTo;
- if (positionInFile < other.positionInFile) {
- compareTo = -1;
- } else if (positionInFile > other.positionInFile) {
- compareTo = 1;
- } else {
- compareTo = 0;
- }
- return compareTo;
- }
-
- @Override
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result
- + (int) (positionInFile ^ (positionInFile >>> 32));
- return result;
- }
-
- @Override
- @SuppressWarnings("PMD")
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- // if (obj == null)
- // return false;
- // if (getClass() != obj.getClass())
- // return false;
- final ToBackupRecord other = (ToBackupRecord) obj;
- if (positionInFile != other.positionInFile)
- return false;
- return true;
- }
-}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -27,16 +27,16 @@
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.file.service.FileIOException;
import net.sf.joafip.file.service.HelperFileUtil;
-import net.sf.joafip.heapfile.entity.IFileStorable;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
-import net.sf.joafip.heapfile.record.entity.ToBackupRecord;
-import net.sf.joafip.heapfile.service.FileForStorable;
-import net.sf.joafip.heapfile.service.IFileForStorable;
import net.sf.joafip.kvstore.entity.EnumFileState;
+import net.sf.joafip.kvstore.entity.IFileStorable;
+import net.sf.joafip.kvstore.entity.ToBackupRecord;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
+import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.IFileForStorable;
import net.sf.joafip.logger.JoafipLogger;
/**
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -19,10 +19,10 @@
import net.sf.joafip.Fortest;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
-import net.sf.joafip.heapfile.service.IFileForStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.IFileForStorable;
/**
* Heap elements manager in heap file interface.<br>
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -1,387 +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.service;
-
-import java.io.File;
-
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.file.service.FileIOException;
-import net.sf.joafip.file.service.IRandomAccessFile;
-import net.sf.joafip.file.service.RandomAccessFileDirectNio;
-import net.sf.joafip.file.service.RandomAccessFileReadWriteCache;
-import net.sf.joafip.heapfile.entity.IFileStorable;
-import net.sf.joafip.heapfile.record.entity.ToBackupRecord;
-import net.sf.joafip.kvstore.service.HeapException;
-import net.sf.joafip.logger.JoafipLogger;
-
-/**
- * to read/write class implementing {@link IFileStorable} to/from file.<br>
- * {@link #open()} and {@link #close()}<br>
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public class FileForStorable implements IFileForStorable {
-
- private static final String FILE_IS_OPENED = "file is opened";
-
- protected final JoafipLogger logger = JoafipLogger.getLogger(getClass());// NOPMD
-
- protected static final String FILE_ALREADY_CLOSED = "file already closed";
-
- protected static final String FILE_NOT_OPENNED = "file not opened";
-
- private static final String FILE_ALREADY_OPENED = "file already opened";
-
- protected static final String FAILED_DELETE_FILE = "failed delete file ";
-
- /** the file object for file heap */
- private final File file;
-
- /** for random read write file access */
- protected IRandomAccessFile randomAccessFile;
-
- /** true if file opened */
- private boolean opened = false;
-
- private Exception opennerTrace;
-
- private Exception closerTrace = new Exception("closer trace");
-
- /**
- * create a file to read from and write to {@link IFileStorable} object.<br>
- * no cache used for file management<br>
- *
- * @param fileName
- * the file name of file to use for storing storable object
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- * if an I/O error occurs while opening the file
- */
- public FileForStorable(final String fileName, final int maxRetry,
- final int retryMsDelay) throws HeapException {
- this(fileName == null ? null : new File(fileName), maxRetry,
- retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * no cache used for file management<br>
- *
- * @param file
- * the file to use for storable object storing
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- * if an I/O error occurs while opening the file
- */
- public FileForStorable(final File file, final int maxRetry,
- final int retryMsDelay) throws HeapException {
- this.file = file;
- randomAccessFile = new RandomAccessFileDirectNio(file, maxRetry,
- retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * file management use read/write cache<br>
- *
- * @param fileName
- * the file name of file to use for object storing
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public FileForStorable(final String fileName, final int pageSize,
- final int maxPage, final int maxRetry, final int retryMsDelay)
- throws HeapException {
- this(fileName == null ? null : new File(fileName), pageSize, maxPage,
- maxRetry, retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- *
- * @param file
- * the file to use for storable object storing
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public FileForStorable(final File file, final int pageSize,
- final int maxPage, final int maxRetry, final int retryMsDelay)
- throws HeapException {
- this.file = file;
- final RandomAccessFileDirectNio randomAccessFileDirect =
- /**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
- randomAccessFile = new RandomAccessFileReadWriteCache(
- randomAccessFileDirect, pageSize, maxPage, maxRetry,
- retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * file management use read/write cache<br>
- *
- * @param file
- * the file to use for storable object storing
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param haveReadCache
- * true if have read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public FileForStorable(final File file, final int pageSize,
- final int maxPage, final boolean haveReadCache, final int maxRetry,
- final int retryMsDelay) {
- this.file = file;
- final RandomAccessFileDirectNio randomAccessFileDirect =
- /**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
- randomAccessFile = new RandomAccessFileReadWriteCache(
- randomAccessFileDirect, pageSize, maxPage, haveReadCache);
- }
-
- @Override
- public void open() throws HeapException {
- if (opened) {
- throw new HeapException(FILE_ALREADY_OPENED, opennerTrace);
- } else {
- try {
- randomAccessFile.open();
- } c...
[truncated message content] |
|
From: <luc...@us...> - 2012-04-17 06:45:15
|
Revision: 3013
http://joafip.svn.sourceforge.net/joafip/?rev=3013&view=rev
Author: luc_peuvrier
Date: 2012-04-17 06:44:59 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
for tests some moves from joafip-heapfile to joafip-kvstore and joafip-file
Modified Paths:
--------------
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java
trunk/joafip-file/src/test/java/net/sf/joafip/file/entity/FileAccessRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.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/TestHeapElementManager.java
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/TestStoreRestore.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java
trunk/joafip-testsuite/pom.xml
trunk/joafip-testsuite/src/main/java/net/sf/joafip/PersistanceTestsNoLongTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/file/FileTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/RecordTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/entity/RecordEntityTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/service/RecordServiceTests.java
Added Paths:
-----------
trunk/joafip-file/src/test/java/net/sf/joafip/file/service/TestRandomAccessFileCache.java
trunk/joafip-kvstore/src/test/java/net/
trunk/joafip-kvstore/src/test/java/net/sf/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/file/service/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/KeyValueStoreTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/entity/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/KVRecordTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/service/
Removed Paths:
-------------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestRandomAccessFileCache.java
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -241,8 +241,8 @@
}
@Override
- protected void writeImpl(final byte[] data,final int offset,final int length)
- throws FileIOException {
+ protected void writeImpl(final byte[] data, final int offset,
+ final int length) throws FileIOException {
try {
randomAccessFile.write(data, offset, length);
} catch (IOException exception) {
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -269,18 +269,18 @@
@Override
public void writeImpl(final byte[] data) throws FileIOException {
- writeImpl(data,0, data.length);
+ writeImpl(data, 0, data.length);
}
@Override
public void writeImpl(final byte[] data, final int length)
throws FileIOException {
- writeImpl(data,0, length);
+ writeImpl(data, 0, length);
}
@Override
- protected void writeImpl(final byte[] data,final int offset,final int length)
- throws FileIOException {
+ protected void writeImpl(final byte[] data, final int offset,
+ final int length) throws FileIOException {
int wrote = 0;
byte[] page;
do {
@@ -294,7 +294,8 @@
} else {
lengthToCopy = inPage;
}
- System.arraycopy(data, offset+wrote, page, positionInPage, lengthToCopy);
+ System.arraycopy(data, offset + wrote, page, positionInPage,
+ lengthToCopy);
wrote += lengthToCopy;
positionInFile += lengthToCopy;
Modified: trunk/joafip-file/src/test/java/net/sf/joafip/file/entity/FileAccessRecord.java
===================================================================
--- trunk/joafip-file/src/test/java/net/sf/joafip/file/entity/FileAccessRecord.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-file/src/test/java/net/sf/joafip/file/entity/FileAccessRecord.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -35,11 +35,11 @@
private final byte[] data;
- public FileAccessRecord(final long positionInFile, final byte[] data,final int offset,
- final int length) {
+ public FileAccessRecord(final long positionInFile, final byte[] data,
+ final int offset, final int length) {
super();
this.positionInFile = positionInFile;
- this.data = Arrays.copyOfRange(data, offset, offset+length);
+ this.data = Arrays.copyOfRange(data, offset, offset + length);
}
public long getPositionInFile() {
Copied: trunk/joafip-file/src/test/java/net/sf/joafip/file/service/TestRandomAccessFileCache.java (from rev 3012, trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestRandomAccessFileCache.java)
===================================================================
--- trunk/joafip-file/src/test/java/net/sf/joafip/file/service/TestRandomAccessFileCache.java (rev 0)
+++ trunk/joafip-file/src/test/java/net/sf/joafip/file/service/TestRandomAccessFileCache.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -0,0 +1,232 @@
+/*
+ * 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.file.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.file.service.FileIOException;
+import net.sf.joafip.file.service.RandomAccessFileDirectNio;
+import net.sf.joafip.file.service.RandomAccessFileReadWriteCache;
+
+@NotStorableClass
+@DoNotTransform
+public class TestRandomAccessFileCache extends AbstractCommonDeleteFileTestCase {
+
+ private static final int NUMBER_OF_PAGE = 10;
+
+ private static final int PAGE_SIZE = 1024;
+
+ private RandomAccessFileReadWriteCache fileCache; // NOPMD
+
+ public TestRandomAccessFileCache() throws TestException {
+ super();
+ }
+
+ public TestRandomAccessFileCache(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()
+ + "/data");
+ // final RandomAccessFileDirect direct = new
+ // RandomAccessFileDirect(file);
+ final RandomAccessFileDirectNio direct = new RandomAccessFileDirectNio(
+ file, 1, 0);
+ fileCache = new RandomAccessFileReadWriteCache(direct, PAGE_SIZE,
+ NUMBER_OF_PAGE);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {// NOPMD override test case
+ try {
+ fileCache.close();
+ } catch (Throwable throwable) {// NOPMD ignore all errors
+ }
+ fileCache = null;// NOPMD
+ super.tearDown();
+ }
+
+ public void testEmptyFile() throws FileIOException {
+ fileCache.open();
+ final byte[] data = new byte[100];
+ assertEquals("must have nothing to read", -1, fileCache.read(data));
+ }
+
+ public void test100bytes() throws FileIOException {// NOPMD
+ fileCache.open();
+ fileCache.seek(0);
+ writeBlock(0);
+ fileCache.close();
+
+ fileCache.open();
+ fileCache.seek(0);
+ assertBlockContent(0);
+ fileCache.close();
+ }
+
+ public void testWroteInCache() throws FileIOException {
+ writeData();
+ assertWroteReading();
+ }
+
+ public void testWroteInFile() throws FileIOException {
+ writeData();
+ fileCache.close();
+ fileCache.clearCache();
+ fileCache.open();
+ assertWroteReading();
+ }
+
+ public void testRandomBlock() throws FileIOException {
+ writeData();
+ fileCache.close();
+ fileCache.clearCache();
+ fileCache.open();
+
+ writeBlock(25, 200);
+ fileCache.seek(50 * 100);
+ assertBlockContent(50);
+ writeBlock(50, 201);
+ assertBlockContent(50, 201);
+ assertBlockContent(25, 200);
+ }
+
+ /**
+ * test page to write are not lost
+ *
+ * @throws FileIOException
+ */
+ public void testToWriteNotLost() throws FileIOException {
+ /*
+ * write 2 NUMBER_OF_PAGE pages
+ */
+ fileCache.open();
+ fileCache.seek(0);
+ byte[] data = new byte[PAGE_SIZE];
+ for (int pageNumber = 0; pageNumber < NUMBER_OF_PAGE * 2; pageNumber++) {
+ for (int index = 0; index < PAGE_SIZE; index++) {
+ data[index] = (byte) pageNumber;
+ }
+ fileCache.write(data);
+ }
+ fileCache.flush();
+ fileCache.close();
+ fileCache.clearCache();
+
+ /*
+ * change value in first page, when read enough to activate old page
+ * clearing
+ */
+ fileCache.open();
+ fileCache.seek(0);
+ for (int index = 0; index < PAGE_SIZE; index++) {
+ data[index] = (byte) 0xff;
+ }
+ fileCache.write(data);
+ for (int pageNumber = 0; pageNumber < NUMBER_OF_PAGE * 2; pageNumber++) {
+ fileCache.read(data);
+ }
+ fileCache.flush();
+ fileCache.close();
+ fileCache.clearCache();
+ /*
+ * check if first page wrote
+ */
+ fileCache.open();
+ fileCache.seek(0);
+ fileCache.read(data);
+ for (int index = 0; index < PAGE_SIZE; index++) {
+ assertEquals("not wrote data", (byte) 0xff, data[index]);
+ }
+
+ }
+
+ /**
+ * @throws FileIOException
+ */
+ private void assertWroteReading() throws FileIOException {
+ fileCache.seek(0);
+ for (int count = 0; count < 100; count++) {
+ assertBlockContent(count);
+ }
+ }
+
+ private void assertBlockContent(final int block, final int count)
+ throws FileIOException {
+ fileCache.seek(block * 100);
+ assertBlockContent(count);
+ }
+
+ /**
+ * @param count
+ * @throws FileIOException
+ */
+ private void assertBlockContent(final int count) throws FileIOException {
+ final byte[] data = new byte[100];
+ assertEquals("must read 100 bytes (value " + count + ")", 100,
+ fileCache.read(data));
+ for (int index = 0; index < 100; index++) {
+ assertEquals("bad byte value", (byte) count, data[index]);
+ }
+ }
+
+ /**
+ * @throws FileIOException
+ */
+ private void writeData() throws FileIOException {
+ fileCache.open();
+ fileCache.seek(0);
+ for (int count = 0; count < 100; count++) {
+ writeBlock(count);
+ }
+ }
+
+ /**
+ *
+ * @param block
+ * 100 byte block number
+ * @param valueOfAllData
+ * value of all byte in data block
+ * @throws FileIOException
+ */
+ private void writeBlock(final int block, final int valueOfAllData)
+ throws FileIOException {
+ fileCache.seek(block * 100);
+ writeBlock(valueOfAllData);
+ }
+
+ /**
+ * @param valueOfAllData
+ * value of all byte in data block
+ * @throws FileIOException
+ */
+ private void writeBlock(final int valueOfAllData) throws FileIOException {
+ byte[] data = new byte[100];
+ for (int index = 0; index < 100; index++) {
+ data[index] = (byte) valueOfAllData;
+ }
+ fileCache.write(data);
+ }
+}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -17,7 +17,7 @@
package net.sf.joafip.heapfile.record.entity;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.record.service.HeapElementManager;
+import net.sf.joafip.heapfile.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.entity.AbstractFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
@@ -71,7 +71,7 @@
* construct header for reading in heap file or for an empty heap
*
*/
- public HeapHeader(final HeapElementManager heapElementManager) {
+ public HeapHeader(final IHeapElementManager heapElementManager) {
/* always at the begin of the file */
/* length=HEAP_HEADER_SIZE */
super(heapElementManager.getFileForStorable(), 0L/* position */);
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -191,7 +191,7 @@
private boolean openedTransaction = false;
/** the header node */
- private final HeapHeader header;
+ private HeapHeader header;
/** true if data loose, updated by {@link #wasBadFileStableState()} */
private boolean dataLost = false;
@@ -250,7 +250,6 @@
this.clearResizeFile = clearResizeFile;
this.maxFileOperationRetry = maxFileOperationRetry;
this.fileOperationRetryMsDelay = fileOperationRetryMsDelay;
- header = new HeapHeader(this);
}
/**
@@ -295,7 +294,6 @@
this.clearResizeFile = clearResizeFile;
this.maxFileOperationRetry = maxFileOperationRetry;
this.fileOperationRetryMsDelay = fileOperationRetryMsDelay;
- header = new HeapHeader(this);
}
@Override
@@ -1021,25 +1019,12 @@
return heapRecord;
}
- /**
- * the heap size is the current byte position after the last record
- *
- * @return the heap size in bytes
- * @throws HeapException
- */
@Override
- public long heapSize() throws HeapException {
- assertTransactionOpened();
- return header.getEndOfRecordPositionInFile();
+ public void setHeapHeader(final HeapHeader heapHeader) throws HeapException {
+ this.header = heapHeader;
}
@Override
- public long getLastRecordPositionInFile() throws HeapException {
- assertTransactionOpened();
- return header.getLastRecordPositionInFile();
- }
-
- @Override
public HeapHeader getHeapHeader() throws HeapException {
assertTransactionOpened();
return header;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -16,7 +16,6 @@
*/
package net.sf.joafip.heapfile.record.service;
-import net.sf.joafip.Fortest;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
@@ -130,7 +129,15 @@
boolean isTransactionOpened();
/**
+ * set heap header
*
+ * @param heapHeader
+ * @throws HeapException
+ */
+ void setHeapHeader(HeapHeader heapHeader) throws HeapException;
+
+ /**
+ *
* @return the heap header in file
* @throws HeapException
*/
@@ -187,21 +194,6 @@
void delete(long positionInFile) throws HeapException;
/**
- *
- * @return heap file size in bytes
- * @throws HeapException
- */
- long heapSize() throws HeapException;
-
- /**
- *
- * @return last record in file position
- * @throws HeapException
- */
- @Fortest
- long getLastRecordPositionInFile() throws HeapException;
-
- /**
* @return file for storage size
* @throws HeapException
*/
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-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -192,6 +192,7 @@
deleteRenaming, clearResizeFile, maxFileOperationRetry,
fileOperationRetryMsDelay, openFileTraceFile);
}
+ heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
final HeapFreeNodeManager heapFreeNodeManager = new HeapFreeNodeManager(
heapElementManager);
freeNodeTree = new RedBlackTree<Integer>(heapFreeNodeManager, false,
@@ -1084,7 +1085,8 @@
@Override
protected long heapSizeImpl() throws HeapException {
- return heapElementManager.heapSize();
+ final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ return heapHeader.getEndOfRecordPositionInFile();
}
@Override
@@ -1232,7 +1234,8 @@
@Fortest
@Override
public long getLastRecordPositionInFile() throws HeapException {
- final long lastRecordPositionInFile = heapElementManager
+ final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final long lastRecordPositionInFile = heapHeader
.getLastRecordPositionInFile();
return lastRecordPositionInFile;
}
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-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -81,6 +81,7 @@
heapElementManager = new HeapElementManager(fileForStorable,
stateDataFile, backupFileForStorable, stateDataBackupFile,
globalStateFlag, false, false, 1, 0, openFileTraceFile);
+ heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
heapElementManager.startService();
heapElementManager.openTransaction();
Deleted: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -1,206 +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.entity;
-
-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.kvstore.entity.AbstractFileStorable;
-import net.sf.joafip.kvstore.service.FileForStorable;
-import net.sf.joafip.kvstore.service.HeapException;
-
-@NotStorableClass
-@DoNotTransform
-public class TestAbstractFileStorable extends AbstractCommonDeleteFileTestCase {// NOPMD
-
- private String fileName;
-
- private static final String DATA1 = "abcdefghijkl";
-
- private static final String DATA2 = "0123456789abcdefghijkl";
-
- @NotStorableClass
- private class Storable extends AbstractFileStorable {
-
- public byte data[]; // NOPMD
-
- public int dataSize; // NOPMD
-
- public Storable(final FileForStorable fileForStorable,
- final long positionInFile) {
- super(fileForStorable, positionInFile);
- }
-
- @Override
- protected void valueChangedAction() throws HeapException {
- // no implementation
- }
-
- @Override
- protected int toMarshallSize() throws HeapException {
- return dataSize + 4;
- }
-
- @Override
- protected void unmarshallImpl() throws HeapException {
- readFileToIoBuffer(dataSize + 4);// +4 for crc32
- data = readBytes(dataSize);
- readAndCheckCrc32();
- logger.info("wrote crc32 " + getCrc32() + " pos=" + positionInFile);
- }
-
- @Override
- protected void marshallImpl() throws HeapException {
- writeBytes(data);
- writeCrc32();
- logger.info("wrote crc32 " + getCrc32() + " pos=" + positionInFile);
- }
-
- @Override
- public boolean equals(final Object obj) {// NOPMD hascode not needed
- boolean equals;
- if (obj == null) {
- equals = false;
- } else if (obj instanceof Storable) {
- final Storable storable = (Storable) obj;
- equals = positionInFile == storable.positionInFile;
- if (equals) {
- equals = data.length == storable.data.length;
- }
- for (int index = 0; equals && index < data.length; index++) {
- equals = data[index] == storable.data[index];
- }
- } else {
- equals = false;
- }
- return equals;
- }
-
- };
-
- private Storable storableIn1; // NOPMD
-
- private Storable storableOut1; // NOPMD
-
- private Storable storableIn2; // NOPMD
-
- private Storable storableOut2; // NOPMD
-
- private FileForStorable fileForStorable; // NOPMD
-
- public TestAbstractFileStorable() throws TestException {
- super();
- }
-
- public TestAbstractFileStorable(final String name) throws TestException {
- super(name);
- }
-
- protected void setUp() throws Exception {// NOPMD inherit test case
- super.setUp();
- fileName = TestConstant.getWinRamDiskRuntimeDir() + File.separator
- + "test.dat";
- fileForStorable = new FileForStorable(fileName, 1, 0);
- /* length = DATA1.length() + 4 */
- storableIn1 = new Storable(fileForStorable, 0);
- /* length= DATA1.length() + 4 */
- storableOut1 = new Storable(fileForStorable, 0);
- storableOut1.setValueIsChangedValueToSave();
- /* length= DATA2.length() + 4 : +4 for crc32 */
- storableIn2 = new Storable(fileForStorable, DATA1.length() + 4);
- /* length= DATA2.length() + 4 : +4 for crc32 */
- storableOut2 = new Storable(fileForStorable, DATA1.length() + 4);
- storableOut2.setValueIsChangedValueToSave();
- }
-
- protected void tearDown() throws Exception {// NOPMD
- try {
- fileForStorable.close();
- } catch (Throwable throwable) {// NOPMD
- // ignore error
- }
- fileForStorable = null;// NOPMD
- storableIn1 = null;// NOPMD
- storableOut1 = null;// NOPMD
- storableIn2 = null;// NOPMD
- storableOut2 = null;// NOPMD
- super.tearDown();
- }
-
- public void testInOut1() throws HeapException {// NOPMD assertion in outIn
- new File(fileName).delete();
- outIn();
- }
-
- public void testInOut2() throws HeapException {// NOPMD assertion in out in
- new File(fileName).delete();
- output();
- input();
- }
-
- private void outIn() throws HeapException {
- output();
- input();
- assertEquals("in1 must be equals to out1", storableIn1, storableOut1);
- assertEquals("in2 must be equals to out2", storableIn2, storableOut2);
- }
-
- /**
- * @throws HeapException
- * @throws FileCorruptedException
- */
- private void input() throws HeapException {
- storableIn1.dataSize = DATA1.length();
- storableIn2.dataSize = DATA2.length();
-
- fileForStorable.open();
- // fileForStorable.readStorable(storableIn2);
- storableIn2.readFromFile();
- // fileForStorable.readStorable(storableIn1);
- storableIn1.readFromFile();
- fileForStorable.close();
- }
-
- /**
- * @throws HeapException
- * @throws FileCorruptedException
- */
- private void output() throws HeapException {
- storableOut1.data = DATA1.getBytes();
- storableOut1.dataSize = DATA1.length();
-
- fileForStorable.open();
- // fileForStorable.writeStorable(storableOut1);
- storableOut1.writeToFile();
- fileForStorable.close();
-
- storableOut2.data = DATA2.getBytes();
- storableOut2.dataSize = DATA2.length();
-
- fileForStorable.open();
- // fileForStorable.writeStorable(storableOut2);
- storableOut2.writeToFile();
- // long fileSize = fileForStorable.getFileSize();
- fileForStorable.close();
- // because of cache can not test that
- // assertEquals(DATA1.length() + DATA2.length(), fileSize);
- }
-}
Deleted: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -1,79 +0,0 @@
-/*
- * Copyright 2008 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.entity;
-
-import net.sf.joafip.AbstractJoafipCommonTestCase;
-import net.sf.joafip.DoNotTransform;
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.TestException;
-import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
-
-@NotStorableClass
-@DoNotTransform
-public class TestDataRecordIdentifier extends AbstractJoafipCommonTestCase {
-
- public TestDataRecordIdentifier() throws TestException {
- super();
- }
-
- public TestDataRecordIdentifier(final String name) throws TestException {
- super(name);
- }
-
- public void testSmall() {
- final DataRecordIdentifier identifier0 = new DataRecordIdentifier(0);
-
- assertEquals("id0 long1 must be 0", 0, identifier0.value);
-
- final DataRecordIdentifier identifier1 = new DataRecordIdentifier(1);
-
- assertEquals("id1 long1 must be 1", 1, identifier1.value);
-
- final DataRecordIdentifier identifier0Bis = new DataRecordIdentifier(0);
-
- assertEquals("id0 must be equals to itself", identifier0, identifier0);
- assertEquals("id0 and id0bis must be equals", identifier0,
- identifier0Bis);
- assertEquals("id0 must be equals to itself thru compareTo", 0,
- identifier0.compareTo(identifier0));
- assertEquals("id0 and id0bis must be equals compareTo", 0,
- identifier0.compareTo(identifier0Bis));
- assertEquals("id0 and id0bis must be equals compareTo", 0,
- identifier0Bis.compareTo(identifier0));
- assertTrue("id0 must be less than id1",
- identifier0.compareTo(identifier1) < 0);
- assertTrue("id1 must be greater than id0",
- identifier1.compareTo(identifier0) > 0);
- }
-
- public void testIncremente() {
- final DataRecordIdentifier identifier = new DataRecordIdentifier(0);
- final DataRecordIdentifier nextIdentifier = new DataRecordIdentifier(
- identifier);
- assertCompareWithNext(identifier, nextIdentifier);
- final DataRecordIdentifier expect...
[truncated message content] |
|
From: <luc...@us...> - 2012-04-18 00:30:02
|
Revision: 3015
http://joafip.svn.sourceforge.net/joafip/?rev=3015&view=rev
Author: luc_peuvrier
Date: 2012-04-18 00:29:55 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
HeapElementManager no more dependent of HeapHeader
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.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/service/TestHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-18 00:30:02
|
Revision: 3015
http://joafip.svn.sourceforge.net/joafip/?rev=3015&view=rev
Author: luc_peuvrier
Date: 2012-04-18 00:29:55 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
HeapElementManager no more dependent of HeapHeader
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.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/service/TestHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -665,7 +665,8 @@
public long getNextRecordFilePosition() throws HeapException {
assertAreaSizeKnew();
long nextRecordFilePosition = positionInFile + areaSize;
- final HeapHeader header = heapElementManager.getHeapHeader();
+ final HeapHeader header = (HeapHeader) heapElementManager
+ .getHeapHeader();
if (nextRecordFilePosition >= header.getEndOfRecordPositionInFile()) {
nextRecordFilePosition = -1;
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -39,7 +39,8 @@
public IRBTNode<E> getRootNode() throws RBTException {
try {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
return getRootNode(heapHeader);
} catch (HeapException exception) {
throw new RBTException(exception);
@@ -60,7 +61,7 @@
public void setRootNode(final IRBTNode<E> rootNode) throws RBTException {
final HeapHeader heapHeader;
try {
- heapHeader = heapElementManager.getHeapHeader();
+ heapHeader = (HeapHeader) heapElementManager.getHeapHeader();
} catch (HeapException exception) {
throw new RBTException(exception);
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -191,7 +191,7 @@
private boolean openedTransaction = false;
/** the header node */
- private HeapHeader header;
+ private IFileStorable header;
/** true if data loose, updated by {@link #wasBadFileStableState()} */
private boolean dataLost = false;
@@ -630,7 +630,7 @@
openFile();
}
} else {
- readHeader(header);
+ header.readFromFile();
}
openedTransaction = true;
} catch (HeapException exception) {
@@ -781,14 +781,6 @@
return true;
}
- /**
- * @param heapHeader
- * @throws HeapException
- */
- private void readHeader(final HeapHeader heapHeader) throws HeapException {
- heapHeader.readFromFile();
- }
-
private void save(final Set<ToBackupRecord> toBackupList)
throws HeapException {
long lastWrotePositionInFile = HeapHeader.HEAP_HEADER_SIZE - 1;
@@ -1004,7 +996,7 @@
}
@Override
- public HeapHeader getHeapHeader() throws HeapException {
+ public IFileStorable getHeapHeader() throws HeapException {
assertTransactionOpened();
return header;
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -18,6 +18,7 @@
import net.sf.joafip.heapfile.record.entity.HeapHeader;
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.service.HeapException;
@@ -132,7 +133,7 @@
* @return the heap header in file
* @throws HeapException
*/
- HeapHeader getHeapHeader() throws HeapException;
+ IFileStorable getHeapHeader() throws HeapException;
/**
* read heap record in file
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-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -363,7 +363,8 @@
throws HeapException {
final HeapRecord heapRecord = deleteAndGetDataRecord(heapIdNode);
/* will update heap header for free and used size */
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
heapHeader.addFreeSize(heapRecord.getAreaSize());
long positionInFile = heapRecord.getPreviousRecordPositionInFile();
@@ -582,7 +583,8 @@
@Override
protected DataRecordIdentifier getNextFreeDataRecordIdentifierImpl()
throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
final DataRecordIdentifier dataRecordIdentifier = new DataRecordIdentifier(
heapHeader.getNextDataRecordIdentifier());
return dataRecordIdentifier;
@@ -592,14 +594,16 @@
protected void setNextFreeDataRecordIdentifierImpl(
final DataRecordIdentifier dataRecordIdentifier)
throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
heapHeader.setNextDataRecordIdentifier(dataRecordIdentifier);
}
@Override
protected DataRecordIdentifier getNewDataRecordIdentifierImpl()
throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
final long nextDataRecordIdentifier = heapHeader
.getNextDataRecordIdentifier();
final DataRecordIdentifier dataRecordIdentifier = new DataRecordIdentifier(
@@ -706,7 +710,8 @@
// NO NO NO do not delete, reused as data record
// heapElementManager.delete(heapRecord.getPositionInFile());
/* will update heap header for free and used size */
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
if (newFreeAreaSize >= HeapRecord.MAX_RECORD_HEADER_SIZE
+ MINIMUM_RECORD_DATA_SIZE + 4) {
@@ -764,7 +769,8 @@
* will update heap header last record position in file information, end
* of record position in file, and used size
*/
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
/* position at end of heap */
final long positionInFile = heapHeader.getEndOfRecordPositionInFile();
heapHeader.setEndOfRecordPositionInFile(positionInFile + needAreaSize);
@@ -1074,19 +1080,22 @@
@Override
protected long heapSizeImpl() throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
return heapHeader.getEndOfRecordPositionInFile();
}
@Override
protected long freeSizeImpl() throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
return heapHeader.getFreeSize();
}
@Override
protected long usedSizeImpl() throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
return heapHeader.getUsedSize();
}
@@ -1223,7 +1232,8 @@
@Fortest
@Override
public long getLastRecordPositionInFile() throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
final long lastRecordPositionInFile = heapHeader
.getLastRecordPositionInFile();
return lastRecordPositionInFile;
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -454,7 +454,8 @@
*/
private HeapHeader getHeapHeaderAndCheckPosition(
final HeapHeader heapHeaderReference) throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
assertEquals("header must be at file beginning", 0,
heapHeader.getPositionInFile());
if (heapHeaderReference != null) {
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -54,7 +54,7 @@
if (heapSize == 0) {
header = null;
} else {
- header = manager.getHeapHeader();
+ header = (HeapHeader) manager.getHeapHeader();
// header = new HeapHeader(manager);
// header.readFromFile();
lastRecordPositionInFile = header.getLastRecordPositionInFile();
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-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -91,6 +91,7 @@
this.positionInFile = positionInFile;
}
+ @Override
public void clear() {
valueChangedToSave = false;
justCreated = true;
@@ -100,6 +101,7 @@
return positionInFile;
}
+ @Override
public void readFromFile() throws HeapException {
// ASSERTX
assert justCreated : ALREADY_READ;
@@ -159,20 +161,12 @@
return justCreated;
}
- /**
- * to know if the value state change
- *
- * @return true if value changed
- */
+ @Override
public boolean isValueChangedToSave() {
return valueChangedToSave;
}
- /**
- * set this record have value changed, so to save
- *
- * @throws HeapException
- */
+ @Override
public void setValueIsChangedValueToSave() throws HeapException {
if (!valueChangedToSave) {
valueChangedToSave = true;
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -48,4 +48,22 @@
*/
void readFromFile() throws HeapException;
+ /**
+ * initial state:no value to save since not read and not write
+ */
+ void clear();
+
+ /**
+ * set this record have value changed, so to save
+ *
+ * @throws HeapException
+ */
+ void setValueIsChangedValueToSave() throws HeapException;
+
+ /**
+ * to know if the value state change
+ *
+ * @return true if value changed
+ */
+ boolean isValueChangedToSave();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-18 03:29:22
|
Revision: 3016
http://joafip.svn.sourceforge.net/joafip/?rev=3016&view=rev
Author: luc_peuvrier
Date: 2012-04-18 03:29:16 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
HeapElementManager no more dependent of HeapRecord
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.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/TestHeapElementManager.java
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/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileDataManagerIntegrityChecker.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
Added Paths:
-----------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-18 03:29:26
|
Revision: 3016
http://joafip.svn.sourceforge.net/joafip/?rev=3016&view=rev
Author: luc_peuvrier
Date: 2012-04-18 03:29:16 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
HeapElementManager no more dependent of HeapRecord
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.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/TestHeapElementManager.java
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/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileDataManagerIntegrityChecker.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
Added Paths:
-----------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -132,12 +132,12 @@
// }
public HeapRecord getHeapRecord() throws HeapException {
- return heapElementManager.readHeapFileDataRecord(positionInFile);
+ return readHeapFileDataRecord(positionInFile);
}
/**
* get this node mirroring in heap file position <br>
- * should be used only by heap red black tree node manager ( sp�cialization
+ * should be used only by heap red black tree node manager ( specialization
* of {@link AbstractHeapNodeManager}) and this<br>
*
* @return the position of this node mirroring in heap file
@@ -283,8 +283,7 @@
*/
HeapRecord heapRecord;
try {
- heapRecord = heapElementManager
- .readHeapFileDataRecord(parentPositionInFile);
+ heapRecord = readHeapFileDataRecord(parentPositionInFile);
} catch (HeapException exception) {
throw new RBTException(exception);
}
@@ -316,8 +315,7 @@
*/
HeapRecord heapRecord;
try {
- heapRecord = heapElementManager
- .readHeapFileDataRecord(leftPositionInFile);
+ heapRecord = readHeapFileDataRecord(leftPositionInFile);
} catch (HeapException exception) {
throw new RBTException(exception);
}
@@ -351,8 +349,7 @@
*/
HeapRecord heapRecord;
try {
- heapRecord = heapElementManager
- .readHeapFileDataRecord(rightPositionInFile);
+ heapRecord = readHeapFileDataRecord(rightPositionInFile);
} catch (HeapException exception) {
throw new RBTException(exception);
}
@@ -507,6 +504,12 @@
}
}
+ private HeapRecord readHeapFileDataRecord(final long positionInFile)
+ throws HeapException {
+ return (HeapRecord) heapElementManager
+ .readHeapFileDataRecord(positionInFile);
+ }
+
@Override
public void detach() {
valueChanged = false;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -51,7 +51,7 @@
public int compareTo(final IRBTComparableNode<Integer> node)
throws RBTException {
int nodeSize;
- nodeSize = ((HeapFreeNode) node).getAreaSize();
+ nodeSize = ((HeapFreeNode) node).getRecordSize();
final int compareTo;
if (areaSize > nodeSize) {
compareTo = 1;
@@ -75,7 +75,7 @@
return compareTo;
}
- public int getAreaSize() {
+ public int getRecordSize() {
return areaSize;
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -84,6 +84,16 @@
}
@Override
+ public long getPreviousRecordPositionInFile() throws HeapException {
+ return -1L;
+ }
+
+ @Override
+ public int getRecordSize() throws HeapException {
+ return HEAP_HEADER_SIZE;
+ }
+
+ @Override
protected void valueChangedAction() throws HeapException {
// no implementation
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -42,11 +42,11 @@
private static final String DATA_SIZE_MISMATCH =
/**/"data size mismatch";
- private static final String CAN_NOT_INCREASE_RECORD_AREA_SIZE =
- /**/"can not increase record area size";
+ private static final String CAN_NOT_INCREASE_RECORD_RECORD_SIZE =
+ /**/"can not increase record size";
- private static final String AREA_SIZE_TO_SMALL_FOR_DATA =
- /**/"area size to small for data";
+ private static final String RECORD_SIZE_TO_SMALL_FOR_DATA =
+ /**/"record size to small for data";
private static final String NO_DATA_TO_WRITE_SET =
/**/"no data to write set";
@@ -129,8 +129,8 @@
private HeapFreeNode freeNode;
- /** the area size in file ( record header size + data size ) */
- private Integer areaSize;
+ /** the record size ( record header size + data size ) */
+ private int recordSize;
private int dataRecordHeaderSize;
@@ -169,15 +169,15 @@
* @param dataAssociatedSize
* size of associated data if not a free record, else it is the
* free space
- * @param areaSize
+ * @param recordSize
* area size for this record
* @throws HeapException
*/
public HeapRecord(final IHeapElementManager heapElementManager,
final long positionInFile, final Long previousRecordPositionInFile,
final DataRecordIdentifier nodeIdentifier,
- final boolean freeRecord, final Integer dataAssociatedSize,
- final Integer areaSize) throws HeapException {
+ final boolean freeRecord, final int dataAssociatedSize,
+ final int recordSize) throws HeapException {
/* length=areaSize */
super(heapElementManager.getFileForStorable(), positionInFile);
this.heapElementManager = heapElementManager;
@@ -190,28 +190,49 @@
*/
// ASSERTX
assert assertAreaSizeForData(freeRecord, nodeIdentifier,
- dataAssociatedSize, areaSize);
- this.areaSize = areaSize;
+ dataAssociatedSize, recordSize);
+ this.recordSize = recordSize;
this.nodeIdentifier = nodeIdentifier;
clearNodeData();
// ASSERTX
assert assertPreviousPositionInFile();
}
+ /**
+ * construction for reading, unknown data associated size, and unknown node
+ * identification<br>
+ * should be only used bye {@link HeapElementManager}<br>
+ *
+ * @param heapElementManager
+ * heap header and record manager in heap file
+ * @param positionInFile
+ * record position in file
+ * @throws HeapException
+ */
+ public HeapRecord(final IHeapElementManager heapElementManager,
+ final long positionInFile) throws HeapException {
+ this(heapElementManager, positionInFile,
+ /**/null/* previous record position in file unknown */,
+ /**/null/* node identification unknown */,
+ /**/false/* a data record is not a free record */,
+ /**/0/* Unknown data Associated Size */,
+ /**/0/* Unknown areaSize */);
+ }
+
private boolean assertAreaSizeForData(final boolean freeRecord,
final DataRecordIdentifier nodeIdentifier,
- final Integer dataAssociatedSize, final Integer areaSize)
+ final int dataAssociatedSize, final int recordSize)
throws HeapException {
// if (!freeRecord && areaSize != null
// && areaSize < MAX_RECORD_HEADER_SIZE + dataAssociatedSize + 4) {
if (!freeRecord
- && areaSize != null
- && areaSize < DATA_RECORD_HEADER_SIZE
+ && recordSize != 0
+ && recordSize < DATA_RECORD_HEADER_SIZE
+ nodeIdentifier.getKeyDataSize() + dataAssociatedSize
+ 4) {
- logger.fatal(AREA_SIZE_TO_SMALL_FOR_DATA);
+ logger.fatal(RECORD_SIZE_TO_SMALL_FOR_DATA);
throw new HeapException(new HeapException(
- AREA_SIZE_TO_SMALL_FOR_DATA));
+ RECORD_SIZE_TO_SMALL_FOR_DATA));
}
return true;
}
@@ -235,27 +256,6 @@
return true;
}
- /**
- * construction for reading, unknown data associated size, and unknown node
- * identification<br>
- * should be only used bye {@link HeapElementManager}<br>
- *
- * @param heapElementManager
- * heap header and record manager in heap file
- * @param positionInFile
- * record position in file
- * @throws HeapException
- */
- public HeapRecord(final IHeapElementManager heapElementManager,
- final long positionInFile) throws HeapException {
- this(heapElementManager, positionInFile,
- /**/null/* previous record position in file unknown */,
- /**/null/* node identification unknown */,
- /**/false/* a data record is not a free record */,
- /**/null/* Unknown data Associated Size */,
- /**/null/* Unknown areaSize */);
- }
-
@Override
protected void valueChangedAction() throws HeapException {
/*
@@ -273,26 +273,26 @@
clearNodeData();
}
- public void unfreeRecord(final int dataAssociatedSize, final int areaSize,
- final DataRecordIdentifier nodeIdentifier, final boolean manageData)
- throws HeapException {
+ public void unfreeRecord(final int dataAssociatedSize,
+ final int recordSize, final DataRecordIdentifier nodeIdentifier,
+ final boolean manageData) throws HeapException {
// ASSERTX
- assert assertCanUnFreeRecordForAreaSize(areaSize);
- this.areaSize = areaSize;
+ assert assertCanUnFreeRecordForRecordSize(recordSize);
+ this.recordSize = recordSize;
assertedUnfreeRecord(dataAssociatedSize, nodeIdentifier);
}
- private boolean assertCanUnFreeRecordForAreaSize(final int areaSize)
+ private boolean assertCanUnFreeRecordForRecordSize(final int recordSize)
throws HeapException {
if (!freeRecord) {
throw new HeapException("already a free record");
}
- assertAreaSizeKnew();
- if (areaSize > this.areaSize) {
- logger.fatal(CAN_NOT_INCREASE_RECORD_AREA_SIZE + " current size="
- + this.areaSize + " asked size=" + areaSize);
+ assertRecordSizeKnew();
+ if (recordSize > this.recordSize) {
+ logger.fatal(CAN_NOT_INCREASE_RECORD_RECORD_SIZE + " current size="
+ + this.recordSize + " asked size=" + recordSize);
throw new HeapException(new HeapException(
- CAN_NOT_INCREASE_RECORD_AREA_SIZE));
+ CAN_NOT_INCREASE_RECORD_RECORD_SIZE));
}
return true;
}
@@ -309,12 +309,12 @@
if (!freeRecord) {
throw new HeapException("already a free record");
}
- assertAreaSizeKnew();
+ assertRecordSizeKnew();
// dataAssociatedSize + 4 : +4 for crc32
- if (areaSize < MAX_RECORD_HEADER_SIZE + dataAssociatedSize + 4) {
- logger.fatal(AREA_SIZE_TO_SMALL_FOR_DATA);
+ if (recordSize < MAX_RECORD_HEADER_SIZE + dataAssociatedSize + 4) {
+ logger.fatal(RECORD_SIZE_TO_SMALL_FOR_DATA);
throw new HeapException(new HeapException(
- AREA_SIZE_TO_SMALL_FOR_DATA));
+ RECORD_SIZE_TO_SMALL_FOR_DATA));
}
return true;
}
@@ -331,12 +331,12 @@
@Override
protected int toMarshallSize() throws HeapException {
// ASSERTX
- assert assertAreaSizeKnew();
+ assert assertRecordSizeKnew();
int toMarshallSize;
if (freeRecord) {
toMarshallSize = FREE_RECORD_HEADER_SIZE;
} else if (dataValueChanged) {
- toMarshallSize = areaSize;
+ toMarshallSize = recordSize;
} else {
// only header will be write
final byte[] keyData = nodeIdentifier.getKeyData();
@@ -358,8 +358,8 @@
assert previousRecordPositionInFile != null : "previous position in file not defined";
writeLong(previousRecordPositionInFile);
// ASSERTX
- assert assertAreaSizeValue(freeRecord);
- writeInteger(areaSize);
+ assert assertRecordSizeValue(freeRecord);
+ writeInteger(recordSize);
if (freeRecord) {
marshallFreeRecord();
} else {
@@ -493,9 +493,9 @@
freeRecord = readBoolean();
previousRecordPositionInFile = readLong();
assertPreviousPositionInFile();
- areaSize = readInteger();
+ recordSize = readInteger();
// ASSERTX
- assert assertAreaSizeValue(freeRecord);
+ assert assertRecordSizeValue(freeRecord);
if (freeRecord) {
// ASSERTX
assert read >= FREE_RECORD_HEADER_SIZE : "expected a minimum of "
@@ -588,10 +588,10 @@
* @param freeRecord
* @throws HeapException
*/
- private boolean assertAreaSizeValue(final boolean freeRecord)
+ private boolean assertRecordSizeValue(final boolean freeRecord)
throws HeapException {
- if (areaSize == null) {
- throw new HeapException("area size must be defined");
+ if (recordSize <= 0) {
+ throw new HeapException("record size must be defined");
}
final int minimal;
if (freeRecord) {
@@ -599,9 +599,10 @@
} else {
minimal = DATA_RECORD_HEADER_SIZE;
}
- if (areaSize < minimal) {
- throw new HeapException("area size too small: areaSize=" + areaSize
- + ", minimal=" + minimal + ", free record=" + freeRecord);
+ if (recordSize < minimal) {
+ throw new HeapException("record size too small: areaSize="
+ + recordSize + ", minimal=" + minimal + ", free record="
+ + freeRecord);
}
return true;
}
@@ -635,7 +636,7 @@
freeNode = new HeapFreeNode(heapElementManager, positionInFile,
parentPositionInFile, leftPositionInFile,
rightPositionInFile, colorSetted, color, numberOfChild,
- areaSize);
+ recordSize);
}
return freeNode;
}
@@ -649,6 +650,7 @@
return freeRecord;
}
+ @Override
public long getPreviousRecordPositionInFile() throws HeapException {
// ASSERTX
assert previousRecordPositionInFile != null : "previous position in file not defined";
@@ -663,8 +665,8 @@
}
public long getNextRecordFilePosition() throws HeapException {
- assertAreaSizeKnew();
- long nextRecordFilePosition = positionInFile + areaSize;
+ assertRecordSizeKnew();
+ long nextRecordFilePosition = positionInFile + recordSize;
final HeapHeader header = (HeapHeader) heapElementManager
.getHeapHeader();
if (nextRecordFilePosition >= header.getEndOfRecordPositionInFile()) {
@@ -676,9 +678,9 @@
/**
* @throws HeapException
*/
- private boolean assertAreaSizeKnew() throws HeapException {
- if (areaSize == null) {
- throw new HeapException("area size is unknow");
+ private boolean assertRecordSizeKnew() throws HeapException {
+ if (recordSize <= 0) {
+ throw new HeapException("record size is unknow");
}
return true;
}
@@ -693,23 +695,18 @@
return true;
}
- /**
- * get the area in file size ( data size or may be more add to header size )
- *
- * @return the area size in file, null if not defined
- * @throws HeapException
- */
- public int getAreaSize() throws HeapException {
+ @Override
+ public int getRecordSize() throws HeapException {
// ASSERTX
- assert assertAreaSizeKnew();
- return areaSize;
+ assert assertRecordSizeKnew();
+ return recordSize;
}
- public void setAreaSize(final int areaSize) {
+ public void setRecordSize(final int recordSize) {
// only for free node update
- this.areaSize = areaSize;
+ this.recordSize = recordSize;
if (freeNode != null) {
- freeNode.setAreaSize(areaSize);
+ freeNode.setAreaSize(recordSize);
}
}
@@ -821,7 +818,7 @@
// (freeNode != null && freeNode
// .equals(heapRecord.freeNode)))
&&
- /**/integerEquals(areaSize, heapRecord.areaSize)
+ /**/integerEquals(recordSize, heapRecord.recordSize)
&&
/**/integerEquals(dataAssociatedSize,
heapRecord.dataAssociatedSize)
@@ -877,8 +874,8 @@
buffer.append(dataAssociatedSize);
buffer.append("\nnodeIdentifier=");
buffer.append(getNodeIdentifier());
- buffer.append("\nareaSize=");
- buffer.append(areaSize);
+ buffer.append("\nrecordSize=");
+ buffer.append(recordSize);
buffer.append("\ndataAssociated=");
buffer.append(dataAssociated);
return buffer.toString();
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -28,11 +28,9 @@
import net.sf.joafip.file.service.FileIOException;
import net.sf.joafip.file.service.HelperFileUtil;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
-import net.sf.joafip.heapfile.record.entity.HeapRecord;
import net.sf.joafip.kvstore.entity.EnumFileState;
import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.entity.ToBackupRecord;
-import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
@@ -41,7 +39,7 @@
/**
* Heap elements manager in heap file.<br>
- * elements are {@link HeapHeader} and {@link HeapRecord}<br>
+ * elements are one heap header and the heap records<br>
* see {@link IHeapElementManager} for role description<br>
* implement a cache for elements read and to write<br>
* data in the cache that was modified will be saved when closing transaction<br>
@@ -202,11 +200,11 @@
* read are put in cache to guaranty that same object for same record is
* returned in same transaction<br>
*/
- private final Map<Long, HeapRecord> heapRecordToWriteMap =
- /**/new TreeMap<Long, HeapRecord>();
+ private final Map<Long, IFileStorable> heapRecordToWriteMap =
+ /**/new TreeMap<Long, IFileStorable>();
- private final Map<Long, HeapRecord> readHeapRecordMap =
- /**/new TreeMap<Long, HeapRecord>();
+ private final Map<Long, IFileStorable> readHeapRecordMap =
+ /**/new TreeMap<Long, IFileStorable>();
private final boolean fileOpenedInTransaction;
@@ -218,11 +216,14 @@
private final int fileOperationRetryMsDelay;
+ private final IHeapRecordFactory heapRecordFactory;
+
private IDataRecordKeyManager dataRecordKeyManager;
/**
* construction for crash safe mode disabled<br>
*
+ * @param heapRecordFactory
* @param fileForStorable
* data file
* @param deleteRenaming
@@ -231,11 +232,13 @@
* @param fileOperationRetryMsDelay
* @param openFileTraceFile
*/
- public HeapElementManager(final IFileForStorable fileForStorable,
+ public HeapElementManager(final IHeapRecordFactory heapRecordFactory,
+ final IFileForStorable fileForStorable,
final boolean deleteRenaming, final boolean clearResizeFile,
final int maxFileOperationRetry,
final int fileOperationRetryMsDelay, final File openFileTraceFile) {
super();
+ this.heapRecordFactory = heapRecordFactory;
crashSafeMode = false;
fileOpenedInTransaction = false;
this.fileForStorable = fileForStorable;
@@ -253,6 +256,7 @@
/**
* construction for crash safe mode enabled<br>
*
+ * @param heapRecordFactory
* @param fileForStorable
* data file
* @param stateOkFlagFile
@@ -271,14 +275,15 @@
* @throws HeapException
* no files in stable state
*/
- public HeapElementManager(final FileForStorable fileForStorable,
- final File stateOkFlagFile,
+ public HeapElementManager(final IHeapRecordFactory heapRecordFactory,
+ final FileForStorable fileForStorable, final File stateOkFlagFile,
final FileForStorable fileForStorableBackup,
final File stateBackupOkFlagFile, final File globalStateFlagFile,
final boolean deleteRenaming, final boolean clearResizeFile,
final int maxFileOperationRetry,
final int fileOperationRetryMsDelay, final File openFileTraceFile) {
super();
+ this.heapRecordFactory = heapRecordFactory;
crashSafeMode = true;
fileOpenedInTransaction = true;
this.fileForStorable = fileForStorable;
@@ -785,9 +790,9 @@
throws HeapException {
long lastWrotePositionInFile = HeapHeader.HEAP_HEADER_SIZE - 1;
long lastRecordPositionInFile = 0;
- for (Map.Entry<Long, HeapRecord> entry : heapRecordToWriteMap
+ for (Map.Entry<Long, IFileStorable> entry : heapRecordToWriteMap
.entrySet()) {
- final HeapRecord heapRecord = entry.getValue();
+ final IFileStorable heapRecord = entry.getValue();
try {
assert false;
} catch (AssertionError error) {
@@ -821,7 +826,7 @@
previousRecordPositionInFile);
}
lastWrotePositionInFile = recordPositionInFile
- + heapRecord.getAreaSize() - 1;
+ + heapRecord.getRecordSize() - 1;
lastRecordPositionInFile = recordPositionInFile;
}
saveHeapRecord(heapRecord, toBackupList);
@@ -915,7 +920,7 @@
}
}
- private void saveHeapRecord(final HeapRecord heapRecord,
+ private void saveHeapRecord(final IFileStorable heapRecord,
final Set<ToBackupRecord> toBackupList) throws HeapException {
// ASSERTX
assert heapRecord.isValueChangedToSave() : "value not change for:\n"
@@ -943,28 +948,27 @@
final long previousRecordPositionInFile) throws HeapException {
String nextOfPrevious;
try {
- final HeapRecord heapRecord2 = readHeapRecordInFile(previousRecordPositionInFile);
+ final IFileStorable heapRecord = readHeapRecordInFile(previousRecordPositionInFile);
final long nNextOfPrevious = previousRecordPositionInFile
- + heapRecord2.getAreaSize();
+ + heapRecord.getRecordSize();
nextOfPrevious = String.valueOf(nNextOfPrevious);
} catch (Exception exception) {
nextOfPrevious = exception.getMessage();
}
- final HeapRecord heapRecord2 = heapRecordToWriteMap
+ final IFileStorable heapRecord = heapRecordToWriteMap
.get(lastRecordPositionInFile);
final long nEndOfFilePosition = lastRecordPositionInFile
- + heapRecord2.getAreaSize();
+ + heapRecord.getRecordSize();
throw new HeapException("for record at " + recordPositionInFile
+ ", bad previous position in file "
+ previousRecordPositionInFile + ", last record position is "
+ lastRecordPositionInFile + ",next of previous position "
+ nextOfPrevious + ",next of last " + nEndOfFilePosition
- + ", last is free " + heapRecord2.isFreeRecord()
- + ", last size " + heapRecord2.getAreaSize() + ", "
- + Thread.currentThread().getName());
+ + Thread.currentThread().getName() + "\nrecord:\n"
+ + heapRecord.toString());
}
/**
@@ -975,9 +979,10 @@
* @return
* @throws HeapException
*/
- private HeapRecord readHeapRecordInFile(final long positionInFile)
+ private IFileStorable readHeapRecordInFile(final long positionInFile)
throws HeapException {
- final HeapRecord heapRecord = new HeapRecord(this, positionInFile);
+ final IFileStorable heapRecord = heapRecordFactory.createHeapRecord(
+ this, positionInFile);
try {
heapRecord.readFromFile();
} catch (HeapException exception) {
@@ -1002,7 +1007,7 @@
}
@Override
- public HeapRecord readHeapFileDataRecord(final long positionInFile)
+ public IFileStorable readHeapFileDataRecord(final long positionInFile)
throws HeapException {
assertTransactionOpened();
// ASSERTX
@@ -1012,13 +1017,14 @@
* same record is returned in same transaction<br>
*/
- HeapRecord heapRecord;
+ IFileStorable heapRecord;
heapRecord = heapRecordToWriteMap.get(positionInFile);
if (heapRecord == null) {
heapRecord = readHeapRecordMap.get(positionInFile);
}
if (heapRecord == null) {
- heapRecord = new HeapRecord(this, positionInFile);
+ heapRecord = heapRecordFactory.createHeapRecord(this,
+ positionInFile);
try {
heapRecord.readFromFile();
} catch (HeapException exception) {
@@ -1035,22 +1041,26 @@
private boolean assertPositionInFile(final long positionInFile)
throws HeapException {
- if (positionInFile < HeapHeader.HEAP_HEADER_SIZE) {
+ if (positionInFile < header.getRecordSize()) {
LOGGER.fatal(READ_HEAP_FILE_NODE_FAILED + " position in heap file "
+ positionInFile + " in header of size="
- + HeapHeader.HEAP_HEADER_SIZE);
+ + header.getRecordSize());
throw new HeapException(READ_HEAP_FILE_NODE_FAILED);
}
return true;
}
@Override
- public void appendHeapFileRecord(final HeapRecord heapRecord)
+ public void appendHeapFileRecord(final IFileStorable heapRecord)
throws HeapException {
final long positionInFile = heapRecord.getPositionInFile();
- HeapRecord previous;
- previous = heapRecordToWriteMap.put(positionInFile, heapRecord);
// ASSERTX
+ assert assertTransactionOpened();
+ // ASSERTX
+ assert assertPositionInFile(positionInFile);
+ IFileStorable previous = heapRecordToWriteMap.put(positionInFile,
+ heapRecord);
+ // ASSERTX
assert assertNoPreviousOrPreviousSameAsCurrent(previous, heapRecord);
if (previous == null) {
previous = readHeapRecordMap.remove(positionInFile);
@@ -1062,38 +1072,8 @@
}
}
- @Override
- public HeapRecord newHeapFileRecord(final long positionInFile,
- final long previousRecordPositionInFile,
- final DataRecordIdentifier nodeIdentification,
- final boolean freeRecord, final Integer dataAssociatedSize,
- final int areaSize) throws HeapException {
- // ASSERTX
- assert assertTransactionOpened();
- // ASSERTX
- assert assertPositionInFile(positionInFile);
- // ASSERTX
- assert !readHeapRecordMap.containsKey(positionInFile) : "must not exist in read cache";
- final HeapRecord heapRecord = new HeapRecord(this, positionInFile,
- previousRecordPositionInFile, nodeIdentification, freeRecord,
- dataAssociatedSize, areaSize);
- final HeapRecord previous = heapRecordToWriteMap.put(positionInFile,
- heapRecord);
- // ASSERTX
- assert assertNoPrevious(heapRecord, previous);
- return heapRecord;
- }
-
- private boolean assertNoPrevious(final HeapRecord heapRecord,
- final HeapRecord previous) throws HeapException {
- if (previous != null) {
- mustNotHavePreviousException(previous, heapRecord);
- }
- return true;
- }
-
private boolean assertNoPreviousOrPreviousSameAsCurrent(
- final HeapRecord previous, final HeapRecord current)
+ final IFileStorable previous, final IFileStorable current)
throws HeapException {
if (previous != null && previous != current) {// NOPMD I want to compare
// reference
@@ -1102,8 +1082,8 @@
return true;
}
- private void mustNotHavePreviousException(final HeapRecord previous,
- final HeapRecord current) throws HeapException {
+ private void mustNotHavePreviousException(final IFileStorable previous,
+ final IFileStorable current) throws HeapException {
throw new HeapException(
"must not have a previous heap record: current=\n"
+ current.toString() + "\nprevious=\n"
@@ -1141,7 +1121,7 @@
* @return heap record in read cache for position in file, null if none
*/
@Fortest
- public HeapRecord getHeapFileRecordInReadCache(final long positionInFile) {
+ public IFileStorable getHeapFileRecordInReadCache(final long positionInFile) {
return readHeapRecordMap.get(positionInFile);
}
@@ -1153,7 +1133,7 @@
* @return heap record in write cache for position in file, null if none
*/
@Fortest
- public HeapRecord getHeapFileRecordInWriteCache(final long positionInFile) {
+ public IFileStorable getHeapFileRecordInWriteCache(final long positionInFile) {
return heapRecordToWriteMap.get(positionInFile);
}
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -57,7 +57,7 @@
if (freeRootNodeFilePosition == -1) {
heapFreeRootNode = null;
} else {
- final HeapRecord heapRecord = heapElementManager
+ final HeapRecord heapRecord = (HeapRecord) heapElementManager
.readHeapFileDataRecord(freeRootNodeFilePosition);
heapFreeRootNode = (HeapFreeNode) heapRecord.getFreeNode();
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.java
==============...
[truncated message content] |
|
From: <luc...@us...> - 2012-04-18 08:20:12
|
Revision: 3017
http://joafip.svn.sourceforge.net/joafip/?rev=3017&view=rev
Author: luc_peuvrier
Date: 2012-04-18 08:20:01 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
changes for heap element manager tests
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/InErrorTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/service/RecordServiceTests.java
Added Paths:
-----------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-18 08:49:16
|
Revision: 3018
http://joafip.svn.sourceforge.net/joafip/?rev=3018&view=rev
Author: luc_peuvrier
Date: 2012-04-18 08:49:04 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
indempendant HeapElementManager move in joafip-kvstore project
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapIdNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.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-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileDataManagerIntegrityChecker.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
Added Paths:
-----------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManager.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/heapfile/record/entity/RecordForTest.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-18 08:20:13
|
Revision: 3017
http://joafip.svn.sourceforge.net/joafip/?rev=3017&view=rev
Author: luc_peuvrier
Date: 2012-04-18 08:20:01 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
changes for heap element manager tests
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/InErrorTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/service/RecordServiceTests.java
Added Paths:
-----------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 03:29:16 UTC (rev 3016)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -996,7 +996,8 @@
}
@Override
- public void setHeapHeader(final HeapHeader heapHeader) throws HeapException {
+ public void setHeapHeader(final IFileStorable heapHeader)
+ throws HeapException {
this.header = heapHeader;
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-18 03:29:16 UTC (rev 3016)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -124,7 +124,7 @@
* @param heapHeader
* @throws HeapException
*/
- void setHeapHeader(HeapHeader heapHeader) throws HeapException;
+ void setHeapHeader(IFileStorable heapHeader) throws HeapException;
/**
*
Added: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java (rev 0)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -0,0 +1,114 @@
+package net.sf.joafip.heapfile.record.entity;
+
+/*
+ * 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.
+ */
+
+import net.sf.joafip.heapfile.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class RecordForTest extends AbstractFileStorable {
+
+ private final int recordSize;
+
+ private int value;
+
+ public RecordForTest(final IHeapElementManager heapElementManager,
+ final long positionInFile, final int recordSize) {
+ super(heapElementManager.getFileForStorable(), positionInFile);
+ this.recordSize = recordSize;
+ }
+
+ @Override
+ public long getPreviousRecordPositionInFile() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public int getRecordSize() throws HeapException {
+ return recordSize;
+ }
+
+ @Override
+ protected int toMarshallSize() throws HeapException {
+ return 8;// integer vale and integer crc32
+ }
+
+ @Override
+ protected void valueChangedAction() throws HeapException {
+ // no implementation
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(final int value) throws HeapException {
+ this.value = value;
+ setValueIsChangedValueToSave();
+ }
+
+ @Override
+ protected void unmarshallImpl() throws HeapException {
+ readFileToIoBuffer(8);
+ value = readInteger();
+ readAndCheckCrc32();
+ }
+
+ @Override
+ protected void marshallImpl() throws HeapException {
+ writeInteger(value);
+ writeCrc32();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + recordSize;
+ result = prime * result + value;
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ RecordForTest other = (RecordForTest) obj;
+ if (recordSize != other.recordSize)
+ return false;
+ if (value != other.value)
+ return false;
+ return true;
+ }
+}
Deleted: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-18 03:29:16 UTC (rev 3016)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -1,498 +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.HeapHeader;
-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.service.FileForStorable;
-import net.sf.joafip.kvstore.service.HeapException;
-import net.sf.joafip.redblacktree.entity.IRBTNode;
-import net.sf.joafip.redblacktree.service.RBTException;
-
-@NotStorableClass
-@DoNotTransform
-public class TestHeapElementManager extends AbstractCommonDeleteFileTestCase
- implements IHeapRecordFactory {// NOPMD
-
- private FileForStorable fileForStorable; // NOPMD
-
- private FileForStorable backupFileForStorable; // NOPMD
-
- private HeapElementManager heapElementManager; // NOPMD
-
- /** first record position */
- private long record1pos; // NOPMD
-
- /** second record position */
- private long record2pos; // NOPMD
-
- /** first record appended */
- private HeapRecord heapRecordAppened1; // NOPMD
-
- /** second record appended */
- private HeapRecord heapRecordAppened2; // NOPMD
-
- public TestHeapElementManager() throws TestException {
- super();
- }
-
- public TestHeapElementManager(final String name) throws TestException {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {// NOPMD override test case
- super.setUp();
- final String runtimePath = TestConstant.getWinRamDiskRuntimeDir();
-
- final File dataFile = new File(runtimePath + File.separator
- + "test.dat");
-
- final File backupFile = new File(runtimePath + File.separator
- + "backup.dat");
-
- final File stateDataBackupFile;
- stateDataBackupFile = new File(runtimePath + File.separator
- + "backup.flag");
-
- final File stateDataFile;
- stateDataFile = new File(runtimePath + File.separator + "data.flag");
- fileForStorable = new FileForStorable(dataFile, 1, 0);
- backupFileForStorable = new FileForStorable(backupFile, 1, 0);
- final File globalStateFile;
- globalStateFile = new File(runtimePath + File.separator + "global.flag");
- final File openFileTraceFile = new File(runtimePath + File.separator
- + "trace.txt");
- heapElementManager = new HeapElementManager(this, fileForStorable,
- stateDataFile, backupFileForStorable, stateDataBackupFile,
- globalStateFile, false, false, 1, 0, openFileTraceFile);
- heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
- }
-
- @Override
- protected void tearDown() throws Exception {// NOPMD override test case
- try {
- if (fileForStorable.isOpened()) {
- fileForStorable.close();
- }
- } catch (Throwable throwable) {// NOPMD ignore all errors
- }
- try {
- if (backupFileForStorable.isOpened()) {
- backupFileForStorable.close();
- }
- } catch (Throwable throwable) {// NOPMD ignore all errors
- }
- fileForStorable = null;// NOPMD
- backupFileForStorable = null;// NOPMD
- heapElementManager = null;// NOPMD
- heapRecordAppened1 = null;// NOPMD
- heapRecordAppened2 = null;// NOPMD
- super.tearDown();
- }
-
- /**
- * test creation of the heap header in empty heap file
- *
- * @throws HeapException
- *
- */
- public void testEmptyHeap() throws HeapException {// NOPMD assertion in
- // method called
-
- /* new heap header creation and write with check */
- final HeapHeader heapHeader1 = appendHeaderInEmptyFile();
-
- /* check the wrote header */
- heapElementManager.startService();
- heapElementManager.openTransaction();
- getHeapHeaderAndCheckPosition(heapHeader1);
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- }
-
- /**
- * test header modification saved in heap file
- *
- * @throws HeapException
- * @throws RBTException
- *
- */
- public void testChangeHeader() throws HeapException, RBTException {
- /* new heap header creation and write with check */
- final HeapHeader heapHeader1 = appendHeaderInEmptyFile();
-
- /* then read header */
- heapElementManager.startService();
- heapElementManager.openTransaction();
- final HeapHeader heapHeader2 = getHeapHeaderAndCheckPosition(heapHeader1);
- /* add heap record */
- final HeapRecord heapRecord = new HeapRecord(heapElementManager,
- /**/HeapHeader.HEAP_HEADER_SIZE/* position in file */);
- // heapHeader2.setFreeRootNodeFilePosition(new HeapFreeNode(
- // heapElementManager, heapRecord).getPositionInFile());
- heapHeader2.setFreeRootNodeFilePosition(heapRecord.getPositionInFile());
- // heapHeader2.setIdRootNodeFilePosition(new HeapIdNode(
- // heapElementManager, heapRecord).getPositionInFile());
- heapHeader2.setIdRootNodeFilePosition(heapRecord.getPositionInFile());
- /* write modifications */
- heapElementManager.closeTransaction();
-
- /* read the last modification */
- heapElementManager.openTransaction();
- final HeapHeader heapHeader3 = getHeapHeaderAndCheckPosition(heapHeader2);
-
- /* check modifications */
- assertEquals("FreeRootNodeFilePosition must be "
- + HeapHeader.HEAP_HEADER_SIZE, HeapHeader.HEAP_HEADER_SIZE,
- heapHeader3.getFreeRootNodeFilePosition());
-
- assertEquals("IdRootNodeFilePosition must be "
- + HeapHeader.HEAP_HEADER_SIZE, HeapHeader.HEAP_HEADER_SIZE,
- heapHeader3.getIdRootNodeFilePosition());
-
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- }
-
- /**
- * test append done correctly
- *
- * @throws HeapException
- *
- */
- public void testAppendRecord() throws HeapException {
- appendRecord();
- heapElementManager.startService();
- heapElementManager.openTransaction();
-
- final int dataSize = 100;
- final HeapRecord heapRecord1 = readHeapFileDataRecord(record1pos);
- assertEquals("bad record position", record1pos,
- heapRecord1.getPositionInFile());
- assertEquals("bad record data size", dataSize, heapRecord1
- .getDataAssociatedSize().intValue());
- final byte[] data1 = heapRecord1.getDataAssociated();
- for (int index = 0; index < dataSize; index++) {
- assertEquals("bad record data", index, data1[index]);
- }
- logger.debug("heap record1\n" + heapRecord1.toString());
- assertEquals("read must be equals appened", heapRecordAppened1,
- heapRecord1);
-
- final HeapRecord heapRecord2 = readHeapFileDataRecord(record2pos);
- assertEquals("bad record position", record2pos,
- heapRecord2.getPositionInFile());
- assertEquals("bad record data size", dataSize, heapRecord2
- .getDataAssociatedSize().intValue());
- final byte[] data2 = heapRecord2.getDataAssociated();
- assertNotSame("heap record 1 and 2 must not have the same data", data1,
- data2);
- for (int index = 0; index < 100; index++) {
- assertEquals("bad record data", index, data2[index]);
- }
- logger.debug("heap record2\n" + heapRecord2.toString());
- assertEquals("read must be equals appened", heapRecordAppened2,
- heapRecord2);
-
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- }
-
- public void testUpdateDataRecord() throws HeapException {
- appendRecord();
- final long pos = record1pos;
-
- heapElementManager.startService();
- heapElementManager.openTransaction();
- HeapRecord heapRecord1 = readHeapFileDataRecord(pos);
- byte[] data1 = heapRecord1.getDataAssociated();
- for (int index = 0; index < data1.length; index++) {
- data1[index] = (byte) (data1.length - index);
- }
- heapRecord1.setDataAssociated(data1);
- heapElementManager.closeTransaction();
-
- heapElementManager.openTransaction();
- heapRecord1 = readHeapFileDataRecord(pos);
- data1 = heapRecord1.getDataAssociated();
- for (int index = 0; index < data1.length; index++) {
- assertEquals("bad record data", data1.length - index, data1[index]);
- }
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
-
- }
-
- public void testUpdateNodeRecord() throws HeapException, RBTException {
- appendRecord();
- final long pos = record1pos;
-
- heapElementManager.startService();
-
- heapElementManager.openTransaction();
- HeapRecord heapRecord1 = readHeapFileDataRecord(pos);
-
- try {
- assert false;
- } catch (AssertionError error) {
- try {
- heapRecord1.getFreeNode();
- fail("must not obtain free node");// NOPMD
- } catch (AssertionError error2) {// NOPMD nothing to do when
- // exception thrown
- // expected
- }
- }
- IRBTNode<?> node = heapRecord1.getIdNode();
- boolean color;
- if (node.isColorSetted()) {
- color = node.getColor();
- } else {
- color = true;
- }
- node.setColor(!color);
- assertTrue("value must have changed",
- heapRecord1.isValueChangedToSave());
- heapElementManager.closeTransaction();
-
- heapElementManager.openTransaction();
- heapRecord1 = readHeapFileDataRecord(pos);
- node = heapRecord1.getIdNode();
- assertEquals("color must have changed", !color, node.getColor());
- assertFalse("not modified record", heapRecord1.isValueChangedToSave());
- heapElementManager.closeTransaction();
-
- heapElementManager.openTransaction();
- heapRecord1 = readHeapFileDataRecord(pos);
- heapRecord1.freeRecord();
- try {
- assert false;
- } catch (AssertionError error) {
- try {
- heapRecord1.getIdNode();
- fail("must not obtain id node");// NOPMD
- } catch (AssertionError error2) {// NOPMD nothing to do when
- // exception thrown
- // expected
- }
- }
- node = heapRecord1.getFreeNode();
- if (node.isColorSetted()) {
- color = node.getColor();
- } else {
- color = true;
- }
- node.setColor(!color);
- heapElementManager.closeTransaction();
-
- heapElementManager.openTransaction();
- heapRecord1 = readHeapFileDataRecord(pos);
- node = heapRecord1.getFreeNode();
- assertEquals("color must have changed", !color, node.getColor());
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- }
-
- public void testChangeManageDataMode() throws HeapException {
- appendRecord();
- final long pos = record1pos;
- heapElementManager.startService();
- heapElementManager.openTransaction();
- /*
- * read record 1 whithout data managing and check state
- */
- HeapRecord heapRecord1 = readHeapFileDataRecord(
- /**/pos/* position in file */);
- assertFalse("record1 must be data record", heapRecord1.isFreeRecord());
- assertFalse("record1 must be in state just created",
- heapRecord1.isJustCreated());
- assertTrue("record1 has been read", heapRecord1.isHeaderRead());
- assertFalse("record1 value must not changed state",
- heapRecord1.isValueChangedToSave());
-
- /*
- * set record 1 value changer, check if added to be wrote
- */
- heapRecord1.setValueIsChangedValueToSave();
- assertNotNull("must be in cache",
- heapElementManager.getHeapFileRecordInWriteCache(pos));
-
- // heapRecord1.createDataArea();
-
- heapElementManager.closeTransaction();
- heapElementManager.openTransaction();
-
- /*
- * change to manage data mode
- */
- heapRecord1 = readHeapFileDataRecord(
- /**/pos/* position in file */);
- assertFalse("record1 must be data record", heapRecord1.isFreeRecord());
- assertFalse("must not be just created", heapRecord1.isJustCreated());
- assertTrue("must has been read", heapRecord1.isHeaderRead());
- assertFalse("value changed must not change",
- heapRecord1.isValueChangedToSave());
- assertNotNull("must be in cache",
- heapElementManager.getHeapFileRecordInReadCache(pos));
-
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- }
-
- /**
- * append heap header in heap empty file
- *
- * @return appened heap header
- * @throws HeapException
- *
- */
- private HeapHeader appendHeaderInEmptyFile() throws HeapException {
- heapElementManager.startService();
- heapElementManager.openTransaction();
- final HeapHeader heapHeader1 = getHeapHeaderAndCheckPosition(null);
- assertEquals("FreeRootNodeFilePosition must be -1", -1,
- heapHeader1.getFreeRootNodeFilePosition());
- assertEquals("IdRootNodeFilePosition must be -1", -1,
- heapHeader1.getIdRootNodeFilePosition());
- // assertTrue("created header must be to save", heapHeader1
- // .isValueChangedToSave());
- assertFalse("created header must be saved",
- heapHeader1.isValueChangedToSave());
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- assertFalse("saving implies no more value changed",
- heapHeader1.isValueChangedToSave());
- assertFalse("just created must be false", heapHeader1.isJustCreated());
- return heapHeader1;
- }
-
- /**
- * append two records
- *
- * @throws HeapException
- */
- private void appendRecord() throws HeapException {
- appendHeaderInEmptyFile();
- heapElementManager.startService();
- heapElementManager.openTransaction();
- record1pos = HeapHeader.HEAP_HEADER_SIZE;
- final int dataSize = 100;
- final DataRecordIdentifier dataRecordIdentifier = DataRecordIdentifier.ZERO;
- heapRecordAppened1 = new HeapRecord(heapElementManager, record1pos,
- -1L/* prev pos */, dataRecordIdentifier/* id */,
- false/* free */, dataSize, dataSize
- + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
- * area size: +
- * 4 for crc32
- */);
- // heapRecordAppened1 = heapElementManager.newHeapFileRecord(record1pos,
- // -1L/* prev pos */, dataRecordIdentifier/* id */,
- // false/* free */, dataSize, dataSize
- // + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
- // * area size: +
- // * 4 for crc32
- // */);
- heapElementManager.appendHeapFileRecord(heapRecordAppened1);
- try {
- assert false;
- } catch (AssertionError error) {
- try {
- heapRecordAppened1.getDataAssociated();
- fail("there is no data associated to record");
- } catch (AssertionError error2) {// NOPMD
- // expected error
- }
- }
-
- byte[] testData = new byte[dataSize];
- for (int index = 0; index < dataSize; index++) {
- testData[index] = (byte) index;
- }
- heapRecordAppened1.setDataAssociated(testData);
-
- heapElementManager.closeTransaction();
- logger.debug("appened heap record1\n" + heapRecordAppened1.toString());
-
- heapElementManager.openTransaction();
-
- record2pos = record1pos + heapRecordAppened1.getRecordSize();
- heapRecordAppened2 = new HeapRecord(heapElementManager, record2pos,
- record1pos, dataRecordIdentifier/* id */, false/* free */,
- dataSize, dataSize + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
- * 4 for
- * crc32
- */);
- // heapRecordAppened2 = heapElementManager.newHeapFileRecord(record2pos,
- // record1pos, dataRecordIdentifier/* id */, false/* free */,
- // dataSize, dataSize + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
- // * 4 for
- // * crc32
- // */);
- heapElementManager.appendHeapFileRecord(heapRecordAppened2);
- heapRecordAppened2.setDataAssociated(testData);
- heapElementManager.closeTransaction();
- heapElementManager.stopService();
- logger.debug("appened heap record2\n" + heapRecordAppened2.toString());
- }
-
- /**
- * get heap header and check its position
- *
- * @param heapHeaderReference
- *
- * @return heap header
- * @throws HeapException
- */
- private HeapHeader getHeapHeaderAndCheckPosition(
- final HeapHeader heapHeaderReference) throws HeapException {
- final HeapHeader heapHeader = (HeapHeader) heapElementManager
- .getHeapHeader();
- assertEquals("header must be at file beginning", 0,
- heapHeader.getPositionInFile());
- if (heapHeaderReference != null) {
- // header is now the same object
- // assertNotSame("new header must not be same of creation one",
- // heapHeaderReference, heapHeader);
- assertEquals("wrote and read must be equals", heapHeaderReference,
- heapHeader);
- }
- return heapHeader;
- }
-
- private HeapRecord readHeapFileDataRecord(final long positionInFile)
- throws HeapException {
- return (HeapRecord) heapElementManager
- .readHeapFileDataRecord(positionInFile);
- }
-
- @Override
- public IFileStorable createHeapRecord(
- final HeapElementManager heapElementManager,
- final long positionInFile) throws HeapException {
- return new HeapRecord(heapElementManager, positionInFile);
- }
-}
Copied: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java (from rev 3016, trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java)
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java (rev 0)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java 2012-04-18 08:20:01 UTC (rev 3017)
@@ -0,0 +1,499 @@
+/*
+ * 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.HeapHeader;
+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.service.FileForStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.redblacktree.entity.IRBTNode;
+import net.sf.joafip.redblacktree.service.RBTException;
+
+@NotStorableClass
+@DoNotTransform
+public class TestHeapElementManagerWithHeapRecord extends
+ AbstractCommonDeleteFileTestCase implements IHeapRecordFactory {// NOPMD
+
+ private FileForStorable fileForStorable; // NOPMD
+
+ private FileForStorable backupFileForStorable; // NOPMD
+
+ private HeapElementManager heapElementManager; // NOPMD
+
+ /** first record position */
+ private long record1pos; // NOPMD
+
+ /** second record position */
+ private long record2pos; // NOPMD
+
+ /** first record appended */
+ private HeapRecord heapRecordAppened1; // NOPMD
+
+ /** second record appended */
+ private HeapRecord heapRecordAppened2; // NOPMD
+
+ public TestHeapElementManagerWithHeapRecord() throws TestException {
+ super();
+ }
+
+ public TestHeapElementManagerWithHeapRecord(final String name)
+ throws TestException {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {// NOPMD override test case
+ super.setUp();
+ final String runtimePath = TestConstant.getWinRamDiskRuntimeDir();
+
+ final File dataFile = new File(runtimePath + File.separator
+ + "test.dat");
+
+ final File backupFile = new File(runtimePath + File.separator
+ + "backup.dat");
+
+ final File stateDataBackupFile;
+ stateDataBackupFile = new File(runtimePath + File.separator
+ + "backup.flag");
+
+ final File stateDataFile;
+ stateDataFile = new File(runtimePath + File.separator + "data.flag");
+ fileForStorable = new FileForStorable(dataFile, 1, 0);
+ backupFileForStorable = new FileForStorable(backupFile, 1, 0);
+ final File globalStateFile;
+ globalStateFile = new File(runtimePath + File.separator + "global.flag");
+ final File openFileTraceFile = new File(runtimePath + File.separator
+ + "trace.txt");
+ heapElementManager = new HeapElementManager(this, fileForStorable,
+ stateDataFile, backupFileForStorable, stateDataBackupFile,
+ globalStateFile, false, false, 1, 0, openFileTraceFile);
+ heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
+ }
+
+ @Override
+ protected void tearDown() throws Exception {// NOPMD override test case
+ try {
+ if (fileForStorable.isOpened()) {
+ fileForStorable.close();
+ }
+ } catch (Throwable throwable) {// NOPMD ignore all errors
+ }
+ try {
+ if (backupFileForStorable.isOpened()) {
+ backupFileForStorable.close();
+ }
+ } catch (Throwable throwable) {// NOPMD ignore all errors
+ }
+ fileForStorable = null;// NOPMD
+ backupFileForStorable = null;// NOPMD
+ heapElementManager = null;// NOPMD
+ heapRecordAppened1 = null;// NOPMD
+ heapRecordAppened2 = null;// NOPMD
+ super.tearDown();
+ }
+
+ /**
+ * test creation of the heap header in empty heap file
+ *
+ * @throws HeapException
+ *
+ */
+ public void testEmptyHeap() throws HeapException {// NOPMD assertion in
+ // method called
+
+ /* new heap header creation and write with check */
+ final HeapHeader heapHeader1 = appendHeaderInEmptyFile();
+
+ /* check the wrote header */
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ getHeapHeaderAndCheckPosition(heapHeader1);
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ /**
+ * test header modification saved in heap file
+ *
+ * @throws HeapException
+ * @throws RBTException
+ *
+ */
+ public void testChangeHeader() throws HeapException, RBTException {
+ /* new heap header creation and write with check */
+ final HeapHeader heapHeader1 = appendHeaderInEmptyFile();
+
+ /* then read header */
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ final HeapHeader heapHeader2 = getHeapHeaderAndCheckPosition(heapHeader1);
+ /* add heap record */
+ final HeapRecord heapRecord = new HeapRecord(heapElementManager,
+ /**/HeapHeader.HEAP_HEADER_SIZE/* position in file */);
+ // heapHeader2.setFreeRootNodeFilePosition(new HeapFreeNode(
+ // heapElementManager, heapRecord).getPositionInFile());
+ heapHeader2.setFreeRootNodeFilePosition(heapRecord.getPositionInFile());
+ // heapHeader2.setIdRootNodeFilePosition(new HeapIdNode(
+ // heapElementManager, heapRecord).getPositionInFile());
+ heapHeader2.setIdRootNodeFilePosition(heapRecord.getPositionInFile());
+ /* write modifications */
+ heapElementManager.closeTransaction();
+
+ /* read the last modification */
+ heapElementManager.openTransaction();
+ final HeapHeader heapHeader3 = getHeapHeaderAndCheckPosition(heapHeader2);
+
+ /* check modifications */
+ assertEquals("FreeRootNodeFilePosition must be "
+ + HeapHeader.HEAP_HEADER_SIZE, HeapHeader.H...
[truncated message content] |
|
From: <luc...@us...> - 2012-04-18 08:49:15
|
Revision: 3018
http://joafip.svn.sourceforge.net/joafip/?rev=3018&view=rev
Author: luc_peuvrier
Date: 2012-04-18 08:49:04 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
indempendant HeapElementManager move in joafip-kvstore project
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapIdNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.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-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileDataManagerIntegrityChecker.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
Added Paths:
-----------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/service/HeapElementManager.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/heapfile/record/entity/RecordForTest.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -18,7 +18,7 @@
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.heapfile.record.service.AbstractHeapNodeManager;
-import net.sf.joafip.heapfile.record.service.IHeapElementManager;
+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.entity.RBTSentinel;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -17,7 +17,7 @@
package net.sf.joafip.heapfile.record.entity;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTComparableNode;
import net.sf.joafip.redblacktree.service.RBTException;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -17,9 +17,9 @@
package net.sf.joafip.heapfile.record.entity;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.entity.AbstractFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
/**
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapIdNode.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapIdNode.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapIdNode.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -17,8 +17,8 @@
package net.sf.joafip.heapfile.record.entity;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTComparableNode;
import net.sf.joafip.redblacktree.service.RBTException;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -20,11 +20,11 @@
import net.sf.joafip.Fortest;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.record.service.HeapElementManager;
-import net.sf.joafip.heapfile.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.entity.AbstractFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.entity.IDataRecordKey;
+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;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -18,6 +18,7 @@
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.logger.JoafipLogger;
import net.sf.joafip.redblacktree.entity.IRBTNode;
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 08:20:01 UTC (rev 3017)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 08:49:04 UTC (rev 3018)
@@ -1,1140 +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 java.io.PrintStream;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-import net.sf.joafip.Fortest;
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.file.service.FileIOException;
-import net.sf.joafip.file.service.HelperFileUtil;
-import net.sf.joafip.heapfile.record.entity.HeapHeader;
-import net.sf.joafip.kvstore.entity.EnumFileState;
-import net.sf.joafip.kvstore.entity.IFileStorable;
-import net.sf.joafip.kvstore.entity.ToBackupRecord;
-import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
-import net.sf.joafip.kvstore.service.FileForStorable;
-import net.sf.joafip.kvstore.service.HeapException;
-import net.sf.joafip.kvstore.service.IFileForStorable;
-import net.sf.joafip.logger.JoafipLogger;
-
-/**
- * Heap elements manager in heap file.<br>
- * elements are one heap header and the heap records<br>
- * see {@link IHeapElementManager} for role description<br>
- * implement a cache for elements read and to write<br>
- * data in the cache that was modified will be saved when closing transaction<br>
- * <br>
- * cache mechanism:<br>
- * record cache is in {@link #heapRecordToWriteMap} and in
- * {@link #readHeapRecordMap}<br>
- * <br>
- * {@link #readHeapFileDataRecord(long, boolean)} check if record already in
- * cache, if not read it from file and put it in cache ( the record is marked
- * not modified )<br>
- * <br>
- * {@link #newHeapFileRecord(long, long, long, boolean, boolean, int, int)},
- * create a new record and put it in the cache<br>
- * <br>
- * {@link #delete(long)} delete record from the cache<br>
- * <br>
- * {@link #closeTransaction()} write record marked changed from the cache to the
- * files ( see crash safe mechanisms )<br>
- * <br>
- * crash safe mechanism can be turned off<br>
- * <br>
- * crash safe mechanism:<br>
- * <br>
- * to be crash safe file is maintained open for reading, write are not done as
- * soon they are ask but put in the read/write cache. records on the read/write
- * cache marked changed are write to file when {@link #closeTransaction()} is
- * call, that close the file to be sure all is on disk before reopen file for
- * reading<br>
- * <br>
- * {@link #wasBadFileStableState()} must be call before use files to restore
- * stable file state if needed<br>
- * <br>
- * FlagData : flag file indicating data file state stable<br>
- * FlagBackup: flag file indicating backup data file state stable<br>
- * FlagGlobal: flag file indicating backup and data file stable state<br>
- * <br>
- * <span style="font-family: monospace;"><br>
- * FlagGlobal present .===#...................#===<br>
- * .......... absent .....#===================#...<br>
- * .......................|...................|...<br>
- * FlagData present ...=======#...#===============<br>
- * .......... absent .....|...#===#...........|...<br>
- * .......................|...|...|...........|...<br>
- * FlagBackup present .===============#...#=======<br>
- * .......... absent .....|...|...|...#===#...|...<br>
- * .......................|...|...|...|...|...|...<br>
- * ..................... (1) (2) (3) (4) (5) (6) .<br>
- * </span> <br>
- * (1) starting of files access for write<br>
- * (2) starting of data file modification (write)<br>
- * (3) ending of data file modification<br>
- * (4) starting of backup data file modification (write)<br>
- * (5) ending of backup data file modification<br>
- * (6)end of files access for write<br>
- * <br>
- * if all flag file are present then all files are in stable state<br>
- * if 'FlagGlobal' is absent there was a modification crash<br>
- * <ul>
- * <li>if both 'FlagData' and 'FlagBackup' are present then the files are not
- * deteriorated, but backup data may not be up to date</li>
- * <li>if 'FlagData' is absent then data file may be deteriorated, backup file
- * is in stable state ( previous data before last interrupted modification)</li>
- * <li>if 'FlagBackup' is absent then backup data file is deteriorated, data
- * file is in stable state ( contains last modification )</li>
- * </ul>
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public class HeapElementManager implements IHeapElementManager {// NOPMD
-
- private static final JoafipLogger LOGGER = JoafipLogger
- .getLogger(HeapElementManager.class);
-
- private static final String NO_FILES =
- /**/"no files";
-
- private static final String OPEN_FAILED =
- /**/"open failed";
-
- private static final String DATA_FILE_NOT_IN_STABLE_STATE_RESTORED =
- /**/"data file not in stable state, restored";
-
- private static final String BACKUP_FILE_NOT_IN_STABLE_STATE_RESTORED =
- /**/"backup file not in stable state, restored";
-
- private static final String FILES_IN_STABLE_STATE =
- /**/"files in stable state";
-
- private static final String NO_FILES_IN_STABLE_STATE =
- /**/"no files in stable state";
-
- private static final String READ_HEAP_FILE_NODE_FAILED =
- /**/"read heap file node failed";
-
- private static final String WRITE_FILE_HEADER_FAILED =
- /**/"close failed, write file header failed";
-
- private static final String READ_FILE_HEADER_FAILED =
- /**/"open failed, read file header failed";
-
- private static final String RECORD_MANAGER_IS_STARTED =
- /**/"record manager is started";
-
- private static final String RECORD_MANAGER_TRANSACTION_ALREADY_OPENED =
- /**/"record manager transaction already opened";
-
- private static final String RECORD_MANAGER_IS_STOPPED =
- /**/"record manager is stopped";
-
- private static final String RECORD_MANAGER_TRANSACTION_IS_CLOSED =
- /**/"record manager transaction is closed";
-
- private static final HelperFileUtil HELPER_FILE_UTIL = HelperFileUtil
- .getInstance();
-
- /** true if crash safe mode enabled */
- private final boolean crashSafeMode;
-
- /** file for {@link IFileStorable} object: header and nodes */
- private final IFileForStorable fileForStorable;
-
- /** backup file for {@link IFileStorable} object: header and nodes */
- private final IFileForStorable fileForStorableBackup;
-
- /** flag file indicating data file state stable */
- private final File stateOkFlagFile;
-
- /** flag file indicating backup data file state stable */
- private final File stateBackupOkFlagFile;
-
- /** flag file indicating backup and data file stable state */
- private final File globalStateFlagFile;
-
- private final File openFileTraceFile;
-
- /** true when record manager service is started */
- private boolean serviceStarted = false;
-
- private Exception starterTrace;
-
- private Exception stopperTrace = new Exception("stopper trace");
-
- /** true when record manager transaction is opened */
- private boolean openedTransaction = false;
-
- /** the header node */
- private IFileStorable header;
-
- /** true if data loose, updated by {@link #wasBadFileStableState()} */
- private boolean dataLost = false;
-
- /**
- * maintain map of to write record identified by start position in file, it
- * is a record cache<br>
- * read are put in cache to guaranty that same object for same record is
- * returned in same transaction<br>
- */
- private final Map<Long, IFileStorable> heapRecordToWriteMap =
- /**/new TreeMap<Long, IFileStorable>();
-
- private final Map<Long, IFileStorable> readHeapRecordMap =
- /**/new TreeMap<Long, IFileStorable>();
-
- private final boolean fileOpenedInTransaction;
-
- private final boolean deleteRenamig;
-
- private final boolean clearResizeFile;
-
- private final int maxFileOperationRetry;
-
- private final int fileOperationRetryMsDelay;
-
- private final IHeapRecordFactory heapRecordFactory;
-
- private IDataRecordKeyManager dataRecordKeyManager;
-
- /**
- * construction for crash safe mode disabled<br>
- *
- * @param heapRecordFactory
- * @param fileForStorable
- * data file
- * @param deleteRenaming
- * @param clearResizeFile
- * @param maxFileOperationRetry
- * @param fileOperationRetryMsDelay
- * @param openFileTraceFile
- */
- public HeapElementManager(final IHeapRecordFactory heapRecordFactory,
- final IFileForStorable fileForStorable,
- final boolean deleteRenaming, final boolean clearResizeFile,
- final int maxFileOperationRetry,
- final int fileOperationRetryMsDelay, final File openFileTraceFile) {
- super();
- this.heapRecordFactory = heapRecordFactory;
- crashSafeMode = false;
- fileOpenedInTransaction = false;
- this.fileForStorable = fileForStorable;
- this.openFileTraceFile = openFileTraceFile;
- this.stateOkFlagFile = null;// NOPMD no state ok flag file
- this.fileForStorableBackup = null;// NOPMD no backup file
- this.stateBackupOkFlagFile = null;// NOPMD no backup state flag file
- this.globalStateFlagFile = null;// NOPMD no global state ok flag file
- this.deleteRenamig = deleteRenaming;
- this.clearResizeFile = clearResizeFile;
- this.maxFileOperationRetry = maxFileOperationRetry;
- this.fileOperationRetryMsDelay = fileOperationRetryMsDelay;
- }
-
- /**
- * construction for crash safe mode enabled<br>
- *
- * @param heapRecordFactory
- * @param fileForStorable
- * data file
- * @param stateOkFlagFile
- * flag file indicating data file state stable
- * @param fileForStorableBackup
- * data backup file
- * @param stateBackupOkFlagFile
- * flag file indicating backup data file state stable
- * @param globalStateFlagFile
- * flag file indicating backup and data file stable state
- * @param deleteRenaming
- * @param clearResizeFile
- * @param maxFileOperationRetry
- * @param fileOperationRetryMsDelay
- * @param openFileTraceFile
- * @throws HeapException
- * no files in stable state
- */
- public HeapElementManager(final IHeapRecordFactory heapRecordFactory,
- final FileForStorable fileForStorable, final File stateOkFlagFile,
- final FileForStorable fileForStorableBackup,
- final File stateBackupOkFlagFile, final File globalStateFlagFile,
- final boolean deleteRenaming, final boolean clearResizeFile,
- final int maxFileOperationRetry,
- final int fileOperationRetryMsDelay, final File openFileTraceFile) {
- super();
- this.heapRecordFactory = heapRecordFactory;
- crashSafeMode = true;
- fileOpenedInTransaction = true;
- this.fileForStorable = fileForStorable;
- this.stateOkFlagFile = stateOkFlagFile;
- this.fileForStorableBackup = fileForStorableBackup;
- this.stateBackupOkFlagFile = stateBackupOkFlagFile;
- assert globalStateFlagFile != null;
- this.globalStateFlagFile = globalStateFlagFile;
- this.openFileTraceFile = openFileTraceFile;
- this.deleteRenamig = deleteRenaming;
- this.clearResizeFile = clearResizeFile;
- this.maxFileOperationRetry = maxFileOperationRetry;
- this.fileOperationRetryMsDelay = fileOperationRetryMsDelay;
- }
-
- @Override
- public IFileForStorable getFileForStorable() {
- return fileForStorable;
- }
-
- @Override
- public long getFileSize() throws HeapException {
- return fileForStorable.getFileSize();
- }
-
- @Override
- public boolean wasBadFileStableState() throws HeapException {// NOPMD
- assertServiceIsStopped();
- final boolean restored;
-
- dataLost = false;
-
- if (crashSafeMode) {
- final boolean globalFlagExists = globalStateFlagFile.exists();
- final boolean dataFlagExists = stateOkFlagFile.exists();
- final boolean backupFlagExists = stateBackupOkFlagFile.exists();
- final boolean dataExists = fileForStorable.getFile().exists();
- final boolean backupExists = fileForStorableBackup.getFile()
- .exists();
-
- if (dataFlagExists && !dataExists) {
- final String message = "backup data flag "
- + stateBackupOkFlagFile.getName()
- + " exists but missing data backup file "
- + fileForStorableBackup.getFile().getName();
- /*
- * need some files maintenance
- */
- LOGGER.fatal(message);
- throw new HeapException(message, EnumFileState.STATE_UNSTABLE);
- } else if (backupFlagExists && !backupExists) {
- final String message = "data flag " + stateOkFlagFile.getName()
- + " exists but missing data file "
- + fileForStorable.getFile().getName();
- /*
- * need some files maintenance
- */
- LOGGER.fatal(message);
- throw new HeapException(message, EnumFileState.STATE_UNSTABLE);
-
- } else if (globalFlagExists) {
- /*
- * global flag exists
- */
- if (dataFlagExists && backupFlagExists) {
- /*
- * data and backup file in stable state
- */
- LOGGER.info(FILES_IN_STABLE_STATE);
- } else {
- /*
- * flag file inconsistency, data and backup flag file must
- * exists if global flag file exist
- */
- /*
- * may be first time case when there is no file present
- */
- inconsistencyCheck(backupExists, dataExists);
- }
- restored = false;
- } else {
- try {
- /*
- * global flag do not exists
- */
- if (dataFlagExists && backupFlagExists) {
- /*
- * backup file may not be up to date, create it from
- * data file
- */
- HELPER_FILE_UTIL.copyFile(fileForStorable.getFile(),
- fileForStorableBackup.getFile());
- LOGGER.warn(BACKUP_FILE_NOT_IN_STABLE_STATE_RESTORED);
- restored = true;
- } else if (!dataFlagExists && backupFlagExists) {
- /*
- * data file not in stable state
- */
- /*
- * since backup file in stable state, create data file
- * from backup file
- */
- HELPER_FILE_UTIL.copyFile(
- fileForStorableBackup.getFile(),
- fileForStorable.getFile());
- LOGGER.warn(DATA_FILE_NOT_IN_STABLE_STATE_RESTORED);
- restored = true;
- dataLost = true;
- } else if (dataFlagExists && !backupFlagExists) {
- /*
- * backup file not in stable state, create it from data
- * file
- */
- HELPER_FILE_UTIL.copyFile(fileForStorable.getFile(),
- fileForStorableBackup.getFile());
- LOGGER.warn(BACKUP_FILE_NOT_IN_STABLE_STATE_RESTORED);
- restored = true;
- } else {
- /*
- * flag file inconsistency, one of data and backup flag
- * file must exists if global flag file not exist
- */
- /*
- * may be first time case when there is no file present
- */
- inconsistencyCheck(backupExists, dataExists);
- restored = false;
- }
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- }
- } else {
- restored = false;
- }
- if (restored) {
- markStableState();
- }
- return restored;
- }
-
- /**
- * file inconsistency checking: detect if first usage when data and backup
- * files absent
- *
- * @param dataExists
- * @param backupExists
- *
- * @throws HeapException
- * file should exist, need some files maintenance
- * @throws HeapException
- */
- private void inconsistencyCheck(final boolean backupExists,
- final boolean dataExists) throws HeapException, HeapException {
- if (dataExists || backupExists) {
- final String message = NO_FILES_IN_STABLE_STATE + ", file "
- + fileForStorable.getFile().getName() + " exist="
- + dataExists + ", file "
- + fileForStorableBackup.getFile().getName() + " exist="
- + backupExists;
- /*
- * need some files maintenance
- */
- LOGGER.fatal(message);
- throw new HeapException(message, EnumFileState.STATE_UNSTABLE);
- } else {
- /*
- * no data, empty
- */
- LOGGER.warn(NO_FILES);
- markStableState();
- }
- }
-
- @Override
- public boolean isDataLost() {
- return dataLost;
- }
-
- /**
- * mark files in stable state, must be call if
- * {@link #wasBadFileStableState()} returned true<br>
- * also use to mark stable after file deletion<br>
- * make able to fix some unstable state from restored state before mark
- * restored files stable<br>
- *
- * @throws HeapException
- * file access error
- */
- private void markStableState() throws HeapException {
- if (crashSafeMode) {
- try {
- HELPER_FILE_UTIL.touchFile(stateBackupOkFlagFile,
- maxFileOperationRetry, fileOperationRetryMsDelay);
- HELPER_FILE_UTIL.touchFile(stateOkFlagFile,
- maxFileOperationRetry, fileOperationRetryMsDelay);
- HELPER_FILE_UTIL.touchFile(globalStateFlagFile,
- maxFileOperationRetry, fileOperationRetryMsDelay);
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- }
- }
-
- @Override
- public void removeFiles() throws HeapException {
- // ASSERTX
- assert assertServiceStoppedOrTransactionClosed();
- // FIXMELUC _should clear flag files
- if (deleteRenamig) {
- fileForStorable.deleteFileIfExistsRenaming();
- } else {
- fileForStorable.deleteFileIfExists();
- }
- if (crashSafeMode) {
- if (deleteRenamig) {
- fileForStorableBackup.deleteFileIfExistsRenaming();
- } else {
- fileForStorableBackup.deleteFileIfExists();
- }
- }
- // ASSERTX
- assert readHeapRecordMap.isEmpty() : "heap record read cache must be empty";
- // ASSERTX
- assert heapRecordToWriteMap.isEmpty() : "heap record write cache must be empty";
- markStableState();
- }
-
- @Override
- public void clear() throws HeapException {
- // ASSERTX
- assert assertTransactionOpened();
- heapRecordToWriteMap.clear();
- readHeapRecordMap.clear();
- if (clearResizeFile) {
- try {
- setStartSaveFlagFile();
- fileForStorable.resetFileSize();
- } catch (HeapException exception) {
- LOGGER.fatal(OPEN_FAILED, exception);
- throw new HeapException(OPEN_FAILED, exception);
- } catch (FileIOException exception) {
- LOGGER.fatal(OPEN_FAILED, exception);
- throw new HeapException(OPEN_FAILED, exception);
- }
- if (crashSafeMode) {
- try {
- setStartBackupFlagFile();
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- try {
- fileForStorableBackup.resetFileSize();
- } catch (HeapException exception) {
- LOGGER.fatal(OPEN_FAILED, exception);
- throw exception;
- }
- }
- try {
- setEndSaveFlagFile();
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- }
- header.clear();
- /* to save new header */
- header.setValueIsChangedValueToSave();
- header.writeToFile();
- flushOnFile();
- }
-
- @Override
- public void startService() throws HeapException {
- // ASSERTX
- assert assertServiceIsStopped();
- starterTrace = new Exception("starter trace");
- serviceStarted = true;
- if (!fileOpenedInTransaction) {
- openFile();
- }
- }
-
- @Override
- public void stopService() throws HeapException {
- // ASSERTX
- assert assertServiceStarted();
- if (openedTransaction) {
- closeTransaction();
- }
- stopperTrace = new Exception("stopper trace");
- serviceStarted = false;
- if (!fileOpenedInTransaction) {
- closeFiles();
- }
- }
-
- @Override
- public boolean isServiceStarted() {
- return serviceStarted;
- }
-
- /**
- * assert service is started
- *
- * @throws HeapException
- * service is stopped
- */
- private boolean assertServiceStarted() throws HeapException {
- if (!serviceStarted) {
- LOGGER.fatal(RECORD_MANAGER_IS_STOPPED);
- throw new HeapException(RECORD_MANAGER_IS_STOPPED, stopperTrace);
- }
- return true;
- }
-
- /**
- * assert service is stopped
- *
- * @throws HeapException
- * service is started
- */
- private boolean assertServiceIsStopped() throws HeapException {
- if (serviceStarted) {
- LOGGER.fatal(RECORD_MANAGER_IS_STARTED);
- throw new HeapException(RECORD_MANAGER_IS_STARTED, starterTrace);
- }
- return true;
- }
-
- @Override
- public void openTransaction() throws HeapException {
- // ASSERTX
- assert assertServiceStartedAndTransactionClosed();
- if (fileOpenedInTransaction) {
- openFile();
- }
- clearHeaprecordToWriteMap();
- readHeapRecordMap.clear();
- try {
- final long fileSize = getFileSize();
- header.clear();
- if (fileSize == 0) {
- /* to save new header */
- header.setValueIsChangedValueToSave();
- header.writeToFile();
- flushOnFile();
- if (fileOpenedInTransaction) {
- closeFiles();
- openFile();
- }
- } else {
- header.readFromFile();
- }
- openedTransaction = true;
- } catch (HeapException exception) {
- LOGGER.fatal(READ_FILE_HEADER_FAILED, exception);
- throw new HeapException(READ_FILE_HEADER_FAILED, exception);
- }
- }
-
- private boolean assertServiceStartedAndTransactionClosed()
- throws HeapException {
- assertServiceStarted();
- assertTransactionClosed();
- return true;
- }
-
- private void assertTransactionClosed() throws HeapException {
- if (openedTransaction) {
- LOGGER.fatal(RECORD_MANAGER_TRANSACTION_ALREADY_OPENED);
- throw new HeapException(RECORD_MANAGER_TRANSACTION_ALREADY_OPENED);
- }
- }
-
- private boolean assertServiceStoppedOrTransactionClosed()
- throws HeapException {
- if (serviceStarted) {
- assertTransactionClosed();
- }
- return true;
- }
-
- private void openFile() throws HeapException {
- if (openFileTraceFile != null) {
- try {
- final PrintStream printStream = new Prin...
[truncated message content] |
|
From: <luc...@us...> - 2012-04-19 01:10:30
|
Revision: 3019
http://joafip.svn.sourceforge.net/joafip/?rev=3019&view=rev
Author: luc_peuvrier
Date: 2012-04-19 01:10:23 +0000 (Thu, 19 Apr 2012)
Log Message:
-----------
bad package changed
Modified Paths:
--------------
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java
Added Paths:
-----------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestAbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestDataRecordIdentifier.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestMarshall.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/
Removed Paths:
-------------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-19 01:10:34
|
Revision: 3019
http://joafip.svn.sourceforge.net/joafip/?rev=3019&view=rev
Author: luc_peuvrier
Date: 2012-04-19 01:10:23 +0000 (Thu, 19 Apr 2012)
Log Message:
-----------
bad package changed
Modified Paths:
--------------
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java
Added Paths:
-----------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestAbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestDataRecordIdentifier.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestMarshall.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/
Removed Paths:
-------------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/
Copied: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java (from rev 3018, trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java)
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java 2012-04-19 01:10:23 UTC (rev 3019)
@@ -0,0 +1,114 @@
+package net.sf.joafip.kvstore.record.entity;
+
+/*
+ * 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.
+ */
+
+import net.sf.joafip.kvstore.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class RecordForTest extends AbstractFileStorable {
+
+ private final int recordSize;
+
+ private int value;
+
+ public RecordForTest(final IHeapElementManager heapElementManager,
+ final long positionInFile, final int recordSize) {
+ super(heapElementManager.getFileForStorable(), positionInFile);
+ this.recordSize = recordSize;
+ }
+
+ @Override
+ public long getPreviousRecordPositionInFile() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public int getRecordSize() throws HeapException {
+ return recordSize;
+ }
+
+ @Override
+ protected int toMarshallSize() throws HeapException {
+ return 8;// integer vale and integer crc32
+ }
+
+ @Override
+ protected void valueChangedAction() throws HeapException {
+ // no implementation
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(final int value) throws HeapException {
+ this.value = value;
+ setValueIsChangedValueToSave();
+ }
+
+ @Override
+ protected void unmarshallImpl() throws HeapException {
+ readFileToIoBuffer(8);
+ value = readInteger();
+ readAndCheckCrc32();
+ }
+
+ @Override
+ protected void marshallImpl() throws HeapException {
+ writeInteger(value);
+ writeCrc32();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + recordSize;
+ result = prime * result + value;
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ RecordForTest other = (RecordForTest) obj;
+ if (recordSize != other.recordSize)
+ return false;
+ if (value != other.value)
+ return false;
+ return true;
+ }
+}
Copied: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestAbstractFileStorable.java (from rev 3018, trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java)
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestAbstractFileStorable.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestAbstractFileStorable.java 2012-04-19 01:10:23 UTC (rev 3019)
@@ -0,0 +1,215 @@
+/*
+ * 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.kvstore.record.entity;
+
+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.kvstore.entity.AbstractFileStorable;
+import net.sf.joafip.kvstore.service.FileForStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+
+@NotStorableClass
+@DoNotTransform
+public class TestAbstractFileStorable extends AbstractCommonDeleteFileTestCase {// NOPMD
+
+ private String fileName;
+
+ private static final String DATA1 = "abcdefghijkl";
+
+ private static final String DATA2 = "0123456789abcdefghijkl";
+
+ @NotStorableClass
+ private class Storable extends AbstractFileStorable {
+
+ public byte data[]; // NOPMD
+
+ public int dataSize; // NOPMD
+
+ public Storable(final FileForStorable fileForStorable,
+ final long positionInFile) {
+ super(fileForStorable, positionInFile);
+ }
+
+ @Override
+ protected void valueChangedAction() throws HeapException {
+ // no implementation
+ }
+
+ @Override
+ protected int toMarshallSize() throws HeapException {
+ return dataSize + 4;
+ }
+
+ @Override
+ protected void unmarshallImpl() throws HeapException {
+ readFileToIoBuffer(dataSize + 4);// +4 for crc32
+ data = readBytes(dataSize);
+ readAndCheckCrc32();
+ logger.info("wrote crc32 " + getCrc32() + " pos=" + positionInFile);
+ }
+
+ @Override
+ protected void marshallImpl() throws HeapException {
+ writeBytes(data);
+ writeCrc32();
+ logger.info("wrote crc32 " + getCrc32() + " pos=" + positionInFile);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {// NOPMD hascode not needed
+ boolean equals;
+ if (obj == null) {
+ equals = false;
+ } else if (obj instanceof Storable) {
+ final Storable storable = (Storable) obj;
+ equals = positionInFile == storable.positionInFile;
+ if (equals) {
+ equals = data.length == storable.data.length;
+ }
+ for (int index = 0; equals && index < data.length; index++) {
+ equals = data[index] == storable.data[index];
+ }
+ } else {
+ equals = false;
+ }
+ return equals;
+ }
+
+ @Override
+ public long getPreviousRecordPositionInFile() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public int getRecordSize() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+ };
+
+ private Storable storableIn1; // NOPMD
+
+ private Storable storableOut1; // NOPMD
+
+ private Storable storableIn2; // NOPMD
+
+ private Storable storableOut2; // NOPMD
+
+ private FileForStorable fileForStorable; // NOPMD
+
+ public TestAbstractFileStorable() throws TestException {
+ super();
+ }
+
+ public TestAbstractFileStorable(final String name) throws TestException {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {// NOPMD inherit test case
+ super.setUp();
+ fileName = TestConstant.getWinRamDiskRuntimeDir() + File.separator
+ + "test.dat";
+ fileForStorable = new FileForStorable(fileName, 1, 0);
+ /* length = DATA1.length() + 4 */
+ storableIn1 = new Storable(fileForStorable, 0);
+ /* length= DATA1.length() + 4 */
+ storableOut1 = new Storable(fileForStorable, 0);
+ storableOut1.setValueIsChangedValueToSave();
+ /* length= DATA2.length() + 4 : +4 for crc32 */
+ storableIn2 = new Storable(fileForStorable, DATA1.length() + 4);
+ /* length= DATA2.length() + 4 : +4 for crc32 */
+ storableOut2 = new Storable(fileForStorable, DATA1.length() + 4);
+ storableOut2.setValueIsChangedValueToSave();
+ }
+
+ protected void tearDown() throws Exception {// NOPMD
+ try {
+ fileForStorable.close();
+ } catch (Throwable throwable) {// NOPMD
+ // ignore error
+ }
+ fileForStorable = null;// NOPMD
+ storableIn1 = null;// NOPMD
+ storableOut1 = null;// NOPMD
+ storableIn2 = null;// NOPMD
+ storableOut2 = null;// NOPMD
+ super.tearDown();
+ }
+
+ public void testInOut1() throws HeapException {// NOPMD assertion in outIn
+ new File(fileName).delete();
+ outIn();
+ }
+
+ public void testInOut2() throws HeapException {// NOPMD assertion in out in
+ new File(fileName).delete();
+ output();
+ input();
+ }
+
+ private void outIn() throws HeapException {
+ output();
+ input();
+ assertEquals("in1 must be equals to out1", storableIn1, storableOut1);
+ assertEquals("in2 must be equals to out2", storableIn2, storableOut2);
+ }
+
+ /**
+ * @throws HeapException
+ * @throws FileCorruptedException
+ */
+ private void input() throws HeapException {
+ storableIn1.dataSize = DATA1.length();
+ storableIn2.dataSize = DATA2.length();
+
+ fileForStorable.open();
+ // fileForStorable.readStorable(storableIn2);
+ storableIn2.readFromFile();
+ // fileForStorable.readStorable(storableIn1);
+ storableIn1.readFromFile();
+ fileForStorable.close();
+ }
+
+ /**
+ * @throws HeapException
+ * @throws FileCorruptedException
+ */
+ private void output() throws HeapException {
+ storableOut1.data = DATA1.getBytes();
+ storableOut1.dataSize = DATA1.length();
+
+ fileForStorable.open();
+ // fileForStorable.writeStorable(storableOut1);
+ storableOut1.writeToFile();
+ fileForStorable.close();
+
+ storableOut2.data = DATA2.getBytes();
+ storableOut2.dataSize = DATA2.length();
+
+ fileForStorable.open();
+ // fileForStorable.writeStorable(storableOut2);
+ storableOut2.writeToFile();
+ // long fileSize = fileForStorable.getFileSize();
+ fileForStorable.close();
+ // because of cache can not test that
+ // assertEquals(DATA1.length() + DATA2.length(), fileSize);
+ }
+}
Copied: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestDataRecordIdentifier.java (from rev 3018, trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java)
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestDataRecordIdentifier.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestDataRecordIdentifier.java 2012-04-19 01:10:23 UTC (rev 3019)
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2008 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.kvstore.record.entity;
+
+import net.sf.joafip.AbstractJoafipCommonTestCase;
+import net.sf.joafip.DoNotTransform;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestException;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+
+@NotStorableClass
+@DoNotTransform
+public class TestDataRecordIdentifier extends AbstractJoafipCommonTestCase {
+
+ public TestDataRecordIdentifier() throws TestException {
+ super();
+ }
+
+ public TestDataRecordIdentifier(final String name) throws TestException {
+ super(name);
+ }
+
+ public void testSmall() {
+ final DataRecordIdentifier identifier0 = new DataRecordIdentifier(0);
+
+ assertEquals("id0 long1 must be 0", 0, identifier0.value);
+
+ final DataRecordIdentifier identifier1 = new DataRecordIdentifier(1);
+
+ assertEquals("id1 long1 must be 1", 1, identifier1.value);
+
+ final DataRecordIdentifier identifier0Bis = new DataRecordIdentifier(0);
+
+ assertEquals("id0 must be equals to itself", identifier0, identifier0);
+ assertEquals("id0 and id0bis must be equals", identifier0,
+ identifier0Bis);
+ assertEquals("id0 must be equals to itself thru compareTo", 0,
+ identifier0.compareTo(identifier0));
+ assertEquals("id0 and id0bis must be equals compareTo", 0,
+ identifier0.compareTo(identifier0Bis));
+ assertEquals("id0 and id0bis must be equals compareTo", 0,
+ identifier0Bis.compareTo(identifier0));
+ assertTrue("id0 must be less than id1",
+ identifier0.compareTo(identifier1) < 0);
+ assertTrue("id1 must be greater than id0",
+ identifier1.compareTo(identifier0) > 0);
+ }
+
+ public void testIncremente() {
+ final DataRecordIdentifier identifier = new DataRecordIdentifier(0);
+ final DataRecordIdentifier nextIdentifier = new DataRecordIdentifier(
+ identifier);
+ assertCompareWithNext(identifier, nextIdentifier);
+ final DataRecordIdentifier expectedNext = new DataRecordIdentifier(1);
+ assertEquals("not expected", expectedNext, nextIdentifier);
+ }
+
+ private void assertCompareWithNext(final DataRecordIdentifier identifier,
+ final DataRecordIdentifier nextIdentifier) {
+ assertTrue("id must be less than next",
+ identifier.compareTo(nextIdentifier) < 0);
+ assertTrue("next must be greater than id",
+ nextIdentifier.compareTo(identifier) > 0);
+ }
+}
Copied: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestMarshall.java (from rev 3018, trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java)
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestMarshall.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/TestMarshall.java 2012-04-19 01:10:23 UTC (rev 3019)
@@ -0,0 +1,223 @@
+/*
+ * 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.kvstore.record.entity;
+
+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.kvstore.entity.AbstractFileStorable;
+import net.sf.joafip.kvstore.service.FileForStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+
+@NotStorableClass
+@DoNotTransform
+public class TestMarshall extends AbstractCommonDeleteFileTestCase {// NOPMD
+
+ @NotStorableClass
+ private class Marshallizable extends AbstractFileStorable {
+
+ public Marshallizable(final FileForStorable fileForStorable) {
+ /* length=8 + 4 + 1 + 4 : 1 long + 1 integer + 1 boolean + 1 integer */
+ super(fileForStorable, 0/* , 8 + 4 + 1 + 4 *//*
+ * 1 long + 1 integer +
+ * 1 boolean + 1 integer
+ */);
+ }
+
+ @Override
+ protected void valueChangedAction() throws HeapException {
+ // no implementation
+ }
+
+ public long longValue;
+
+ public int intValue; // NOPMD
+
+ public boolean booleanValue; // NOPMD
+
+ @Override
+ protected int toMarshallSize() throws HeapException {
+ return 8 + 4 + 1 + 4;
+ }
+
+ @Override
+ protected void marshallImpl() throws HeapException {
+ writeLong(longValue);
+ writeInteger(intValue);
+ writeBoolean(booleanValue);
+ writeCrc32();
+ }
+
+ @Override
+ protected void unmarshallImpl() throws HeapException {
+ readFileToIoBuffer(8 + 4 + 1 + 4);
+ longValue = readLong();
+ intValue = readInteger();
+ booleanValue = readBoolean();
+ readAndCheckCrc32();
+ }
+
+ @Override
+ public long getPreviousRecordPositionInFile() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+
+ @Override
+ public int getRecordSize() throws HeapException {
+ throw new HeapException("unsupported");
+ }
+ };
+
+ private Marshallizable fileStorableForWrite; // NOPMD
+
+ private FileForStorable fileForStorable; // NOPMD
+
+ public TestMarshall() throws TestException {
+ super();
+ }
+
+ public TestMarshall(final String name) throws TestException {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {// NOPMD inherit test case
+ super.setUp();
+ fileForStorable = new FileForStorable(
+ TestConstant.getWinRamDiskRuntimeDir() + File.separator
+ + "test.dat", 1, 0);
+ }
+
+ protected void tearDown() throws Exception {// NOPMD inherit test case
+ try {
+ if (fileForStorable.isOpened()) {
+ fileForStorable.close();
+ }
+ } catch (Throwable throwable) {// NOPMD ignore all errors
+ /* ignore error */
+ }
+ fileStorableForWrite = null;// NOPMD
+ fileForStorable = null;// NOPMD
+ super.tearDown();
+ }
+
+ public void testInOut() throws HeapException {
+ fileStorableForWrite = new Marshallizable(fileForStorable);
+ assertTrue("must be in state just created",
+ fileStorableForWrite.isJustCreated());
+ assertFalse("must be in state value not changed",
+ fileStorableForWrite.isValueChangedToSave());
+ fileStorableForWrite.longValue = 0;
+ fileStorableForWrite.intValue = 0;
+ fileStorableForWrite.booleanValue = false;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ assertFalse("must not be in state just created",
+ fileStorableForWrite.isJustCreated());
+ assertTrue("must be in state value changed",
+ fileStorableForWrite.isValueChangedToSave());
+ check();
+
+ fileStorableForWrite = new Marshallizable(fileForStorable);
+ fileStorableForWrite.longValue = 0xff;
+ fileStorableForWrite.intValue = 0xff;
+ fileStorableForWrite.booleanValue = true;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite = new Marshallizable(fileForStorable);
+ fileStorableForWrite.longValue = 0xff00;
+ fileStorableForWrite.intValue = 0xff00;
+ fileStorableForWrite.booleanValue = false;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite = new Marshallizable(fileForStorable);
+ fileStorableForWrite.longValue = 0xff0000;
+ fileStorableForWrite.intValue = 0xff0000;
+ fileStorableForWrite.booleanValue = true;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite = new Marshallizable(fileForStorable);
+ fileStorableForWrite.longValue = 0xff000000;
+ fileStorableForWrite.intValue = 0xff000000;
+ fileStorableForWrite.booleanValue = false;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite = new Marshallizable(fileForStorable);
+ fileStorableForWrite.longValue = 0xff00000000L;
+ fileStorableForWrite.intValue = 0xff00ff00;
+ fileStorableForWrite.booleanValue = true;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite.longValue = 0xff0000000000L;
+ fileStorableForWrite.intValue = 0x00ff00ff;
+ fileStorableForWrite.booleanValue = false;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite.longValue = 0xff000000000000L;
+ fileStorableForWrite.intValue = 0xf0f0f0f0;
+ fileStorableForWrite.booleanValue = false;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite.longValue = 0xff00000000000000L;
+ fileStorableForWrite.intValue = 0x0f0f0f0f;
+ fileStorableForWrite.booleanValue = true;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+
+ fileStorableForWrite.longValue = 0xff00ff00ff00ff00L;
+ fileStorableForWrite.intValue = 0xffffffff;
+ fileStorableForWrite.booleanValue = false;
+ fileStorableForWrite.setValueIsChangedValueToSave();
+ check();
+ }
+
+ /**
+ * @throws HeapException
+ * @throws FileCorruptedException
+ *
+ */
+ private void check() throws HeapException {
+ final Marshallizable fileStorableForRead;
+ fileForStorable.open();
+ fileStorableForWrite.writeToFile(/* fileForStorable */);
+ assertFalse("must not be in state value changed since just wrote",
+ fileStorableForWrite.isValueChangedToSave());
+ fileStorableForRead = new Marshallizable(fileForStorable);
+ fileStorableForRead.readFromFile(/* fileForStorable */);
+ assertFalse("must be in state just created",
+ fileStorableForRead.isJustCreated());
+ assertFalse("must not be in state value changed",
+ fileStorableForRead.isValueChangedToSave());
+ fileForStorable.close();
+ assertEquals("wrote and read long value must be equals",
+ fileStorableForWrite.longValue, fileStorableForRead.longValue);
+ assertEquals("wrote and read int value must be equals",
+ fileStorableForWrite.intValue, fileStorableForRead.intValue);
+ assertEquals("wrote and read boolean value must be equals",
+ fileStorableForWrite.booleanValue,
+ fileStorableForRead.booleanValue);
+ }
+}
Modified: trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java
===================================================================
--- trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java 2012-04-18 08:49:04 UTC (rev 3018)
+++ trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java 2012-04-19 01:10:23 UTC (rev 3019)
@@ -19,9 +19,6 @@
import junit.framework.Test;
import junit.framework.TestSuite;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.record.entity.TestAbstractFileStorable;
-import net.sf.joafip.heapfile.record.entity.TestDataRecordIdentifier;
-import net.sf.joafip.heapfile.record.entity.TestMarshall;
@NotStorableClass
public class KVRecordEntityTests {// NOPMD
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-19 02:51:41
|
Revision: 3020
http://joafip.svn.sourceforge.net/joafip/?rev=3020&view=rev
Author: luc_peuvrier
Date: 2012-04-19 02:51:34 +0000 (Thu, 19 Apr 2012)
Log Message:
-----------
test added for HeapElementManager
Modified Paths:
--------------
trunk/joafip-heapfile/pom.xml
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java
Added Paths:
-----------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/AbstractTestHeapElementManager.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/TestHeapElementManager.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-19 02:51:44
|
Revision: 3020
http://joafip.svn.sourceforge.net/joafip/?rev=3020&view=rev
Author: luc_peuvrier
Date: 2012-04-19 02:51:34 +0000 (Thu, 19 Apr 2012)
Log Message:
-----------
test added for HeapElementManager
Modified Paths:
--------------
trunk/joafip-heapfile/pom.xml
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java
Added Paths:
-----------
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/AbstractTestHeapElementManager.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/TestHeapElementManager.java
Modified: trunk/joafip-heapfile/pom.xml
===================================================================
--- trunk/joafip-heapfile/pom.xml 2012-04-19 01:10:23 UTC (rev 3019)
+++ trunk/joafip-heapfile/pom.xml 2012-04-19 02:51:34 UTC (rev 3020)
@@ -41,6 +41,14 @@
<dependency>
<groupId>net.sf.joafip</groupId>
+ <artifactId>joafip-kvstore</artifactId>
+ <version>4.0.0b8</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sf.joafip</groupId>
<artifactId>joafip-collection</artifactId>
<version>4.0.0b8</version>
<type>test-jar</type>
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-19 01:10:23 UTC (rev 3019)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java 2012-04-19 02:51:34 UTC (rev 3020)
@@ -16,20 +16,15 @@
*/
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.HeapHeader;
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.AbstractTestHeapElementManager;
import net.sf.joafip.kvstore.record.service.HeapElementManager;
-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.entity.IRBTNode;
import net.sf.joafip.redblacktree.service.RBTException;
@@ -37,14 +32,8 @@
@NotStorableClass
@DoNotTransform
public class TestHeapElementManagerWithHeapRecord extends
- AbstractCommonDeleteFileTestCase implements IHeapRecordFactory {// NOPMD
+ AbstractTestHeapElementManager {
- private FileForStorable fileForStorable; // NOPMD
-
- private FileForStorable backupFileForStorable; // NOPMD
-
- private HeapElementManager heapElementManager; // NOPMD
-
/** first record position */
private long record1pos; // NOPMD
@@ -67,51 +56,13 @@
}
@Override
- protected void setUp() throws Exception {// NOPMD override test case
+ protected void setUp() throws Exception {
super.setUp();
- final String runtimePath = TestConstant.getWinRamDiskRuntimeDir();
-
- final File dataFile = new File(runtimePath + File.separator
- + "test.dat");
-
- final File backupFile = new File(runtimePath + File.separator
- + "backup.dat");
-
- final File stateDataBackupFile;
- stateDataBackupFile = new File(runtimePath + File.separator
- + "backup.flag");
-
- final File stateDataFile;
- stateDataFile = new File(runtimePath + File.separator + "data.flag");
- fileForStorable = new FileForStorable(dataFile, 1, 0);
- backupFileForStorable = new FileForStorable(backupFile, 1, 0);
- final File globalStateFile;
- globalStateFile = new File(runtimePath + File.separator + "global.flag");
- final File openFileTraceFile = new File(runtimePath + File.separator
- + "trace.txt");
- heapElementManager = new HeapElementManager(this, fileForStorable,
- stateDataFile, backupFileForStorable, stateDataBackupFile,
- globalStateFile, false, false, 1, 0, openFileTraceFile);
heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
}
@Override
- protected void tearDown() throws Exception {// NOPMD override test case
- try {
- if (fileForStorable.isOpened()) {
- fileForStorable.close();
- }
- } catch (Throwable throwable) {// NOPMD ignore all errors
- }
- try {
- if (backupFileForStorable.isOpened()) {
- backupFileForStorable.close();
- }
- } catch (Throwable throwable) {// NOPMD ignore all errors
- }
- fileForStorable = null;// NOPMD
- backupFileForStorable = null;// NOPMD
- heapElementManager = null;// NOPMD
+ protected void tearDown() throws Exception {
heapRecordAppened1 = null;// NOPMD
heapRecordAppened2 = null;// NOPMD
super.tearDown();
@@ -152,7 +103,7 @@
heapElementManager.startService();
heapElementManager.openTransaction();
final HeapHeader heapHeader2 = getHeapHeaderAndCheckPosition(heapHeader1);
- /* add heap record */
+ /* create heap record */
final HeapRecord heapRecord = new HeapRecord(heapElementManager,
/**/HeapHeader.HEAP_HEADER_SIZE/* position in file */);
// heapHeader2.setFreeRootNodeFilePosition(new HeapFreeNode(
@@ -381,8 +332,6 @@
heapHeader1.getFreeRootNodeFilePosition());
assertEquals("IdRootNodeFilePosition must be -1", -1,
heapHeader1.getIdRootNodeFilePosition());
- // assertTrue("created header must be to save", heapHeader1
- // .isValueChangedToSave());
assertFalse("created header must be saved",
heapHeader1.isValueChangedToSave());
heapElementManager.closeTransaction();
Modified: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java 2012-04-19 01:10:23 UTC (rev 3019)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/entity/RecordForTest.java 2012-04-19 02:51:34 UTC (rev 3020)
@@ -37,17 +37,21 @@
private final int recordSize;
+ private final long previousRecordPositionInFile;
+
private int value;
public RecordForTest(final IHeapElementManager heapElementManager,
- final long positionInFile, final int recordSize) {
+ final long positionInFile, final int recordSize,
+ final long previousRecordPositionInFile) {
super(heapElementManager.getFileForStorable(), positionInFile);
this.recordSize = recordSize;
+ this.previousRecordPositionInFile = previousRecordPositionInFile;
}
@Override
public long getPreviousRecordPositionInFile() throws HeapException {
- throw new HeapException("unsupported");
+ return previousRecordPositionInFile;
}
@Override
Added: trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/AbstractTestHeapElementManager.java
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/AbstractTestHeapElementManager.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/AbstractTestHeapElementManager.java 2012-04-19 02:51:34 UTC (rev 3020)
@@ -0,0 +1,108 @@
+/*
+ * 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;
+
+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.kvstore.service.FileForStorable;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+@DoNotTransform
+public abstract class AbstractTestHeapElementManager extends
+ AbstractCommonDeleteFileTestCase implements IHeapRecordFactory {
+
+ private FileForStorable fileForStorable; // NOPMD
+
+ private FileForStorable backupFileForStorable; // NOPMD
+
+ protected HeapElementManager heapElementManager; // NOPMD
+
+ public AbstractTestHeapElementManager() throws TestException {
+ super();
+ }
+
+ public AbstractTestHeapElementManager(final String name)
+ throws TestException {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {// NOPMD override test case
+ super.setUp();
+ final String runtimePath = TestConstant.getWinRamDiskRuntimeDir();
+
+ final File dataFile = new File(runtimePath + File.separator
+ + "test.dat");
+
+ final File backupFile = new File(runtimePath + File.separator
+ + "backup.dat");
+
+ final File stateDataBackupFile;
+ stateDataBackupFile = new File(runtimePath + File.separator
+ + "backup.flag");
+
+ final File stateDataFile;
+ stateDataFile = new File(runtimePath + File.separator + "data.flag");
+ fileForStorable = new FileForStorable(dataFile, 1, 0);
+ backupFileForStorable = new FileForStorable(backupFile, 1, 0);
+ final File globalStateFile;
+ globalStateFile = new File(runtimePath + File.separator + "global.flag");
+ final File openFileTraceFile = new File(runtimePath + File.separator
+ + "trace.txt");
+ heapElementManager = new HeapElementManager(this, fileForStorable,
+ stateDataFile, backupFileForStorable, stateDataBackupFile,
+ globalStateFile, false, false, 1, 0, openFileTraceFile);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {// NOPMD override test case
+ try {
+ if (fileForStorable.isOpened()) {
+ fileForStorable.close();
+ }
+ } catch (Throwable throwable) {// NOPMD ignore all errors
+ }
+ try {
+ if (backupFileForStorable.isOpened()) {
+ backupFileForStorable.close();
+ }
+ } catch (Throwable throwable) {// NOPMD ignore all errors
+ }
+ fileForStorable = null;// NOPMD
+ backupFileForStorable = null;// NOPMD
+ heapElementManager = null;// NOPMD
+ super.tearDown();
+ }
+
+}
Added: 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 (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/kvstore/record/service/TestHeapElementManager.java 2012-04-19 02:51:34 UTC (rev 3020)
@@ -0,0 +1,260 @@
+/*
+ * 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;
+
+import net.sf.joafip.DoNotTransform;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestException;
+import net.sf.joafip.kvstore.entity.IFileStorable;
+import net.sf.joafip.kvstore.record.entity.RecordForTest;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.redblacktree.service.RBTException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+@DoNotTransform
+public class TestHeapElementManager extends AbstractTestHeapElementManager {
+
+ private static final int RECORD_SIZE = 100;
+
+ private static final int HEAP_HEADER_VALUE = Integer.MAX_VALUE;
+
+ public TestHeapElementManager() throws TestException {
+ super();
+ }
+
+ public TestHeapElementManager(final String name) throws TestException {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ final RecordForTest heapHeader = new RecordForTest(heapElementManager,
+ 0L, RECORD_SIZE, -1);
+ heapHeader.setValue(HEAP_HEADER_VALUE);
+ heapElementManager.setHeapHeader(heapHeader);
+ }
+
+ /**
+ * test creation of the heap header in empty heap file
+ *
+ * @throws HeapException
+ *
+ */
+ public void testEmptyHeap() throws HeapException {// NOPMD assertion in
+ // method called
+
+ /* new heap header creation and write with check */
+ final RecordForTest heapHeader = appendHeaderInEmptyFile();
+
+ /* check the wrote header */
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ getHeapHeaderAndCheckPosition(heapHeader);
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ /**
+ * test header modification saved in heap file
+ *
+ * @throws HeapException
+ * @throws RBTException
+ *
+ */
+ public void testChangeHeader() throws HeapException, RBTException {
+ /* new heap header creation and write with check */
+ final RecordForTest heapHeader1 = appendHeaderInEmptyFile();
+
+ /* then read header */
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ final RecordForTest heapHeader2 = getHeapHeaderAndCheckPosition(heapHeader1);
+ heapHeader2.setValue(HEAP_HEADER_VALUE - 1);
+ /* write modifications */
+ heapElementManager.closeTransaction();
+
+ /* read the last modification */
+ heapElementManager.openTransaction();
+ final RecordForTest heapHeader3 = getHeapHeaderAndCheckPosition(heapHeader2);
+ /* check modifications */
+ assertEquals("bad value", HEAP_HEADER_VALUE - 1, heapHeader3.getValue());
+
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ public void testAppendRecord() throws HeapException {
+ appendHeaderInEmptyFile();
+ heapElementManager.startService();
+ appendRecords();
+ // check
+ heapElementManager.openTransaction();
+ for (int recordNumber = 0; recordNumber < 100; recordNumber++) {
+ final RecordForTest heapRecord = (RecordForTest) heapElementManager
+ .readHeapFileDataRecord(RECORD_SIZE * (recordNumber + 1));
+ assertEquals("bad value", recordNumber, heapRecord.getValue());
+ }
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ public void testUpdateRecord() throws HeapException {
+ appendHeaderInEmptyFile();
+ heapElementManager.startService();
+ appendRecords();
+ // update
+ heapElementManager.openTransaction();
+ final int recordNumber = 50;
+ RecordForTest heapRecord = new RecordForTest(heapElementManager,
+ RECORD_SIZE * (recordNumber + 1), RECORD_SIZE, RECORD_SIZE
+ * recordNumber);
+ heapRecord.setValue(-recordNumber);
+ heapElementManager.appendHeapFileRecord(heapRecord);
+ heapElementManager.closeTransaction();
+ // check update
+ heapElementManager.openTransaction();
+ heapRecord = (RecordForTest) heapElementManager
+ .readHeapFileDataRecord(RECORD_SIZE * (recordNumber + 1));
+ assertEquals("bad value", -recordNumber, heapRecord.getValue());
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ public void testDeleteRecord() throws HeapException {
+ appendHeaderInEmptyFile();
+ heapElementManager.startService();
+ appendRecords();
+ // update
+ heapElementManager.openTransaction();
+ final int recordNumber = 50;
+ RecordForTest heapRecord = new RecordForTest(heapElementManager,
+ RECORD_SIZE * (recordNumber + 1), RECORD_SIZE, RECORD_SIZE
+ * recordNumber);
+ heapRecord.setValue(-recordNumber);
+ heapElementManager.appendHeapFileRecord(heapRecord);
+ heapElementManager.delete(RECORD_SIZE * (recordNumber + 1));
+ heapElementManager.closeTransaction();
+ // check update
+ heapElementManager.openTransaction();
+ heapRecord = (RecordForTest) heapElementManager
+ .readHeapFileDataRecord(RECORD_SIZE * (recordNumber + 1));
+ assertEquals("bad value", recordNumber, heapRecord.getValue());
+
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ public void testDiscard() throws HeapException {
+ appendHeaderInEmptyFile();
+ heapElementManager.startService();
+ appendRecords();
+ // update
+ heapElementManager.openTransaction();
+ int recordNumber = 50;
+ RecordForTest heapRecord = new RecordForTest(heapElementManager,
+ RECORD_SIZE * (recordNumber + 1), RECORD_SIZE, RECORD_SIZE
+ * recordNumber);
+ heapRecord.setValue(-recordNumber);
+ heapElementManager.appendHeapFileRecord(heapRecord);
+ heapElementManager.closeTransactionDiscardChange();
+ // check
+ heapElementManager.openTransaction();
+ for (recordNumber = 0; recordNumber < 100; recordNumber++) {
+ heapRecord = (RecordForTest) heapElementManager
+ .readHeapFileDataRecord(RECORD_SIZE * (recordNumber + 1));
+ assertEquals("bad value", recordNumber, heapRecord.getValue());
+ }
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ }
+
+ /**
+ * append heap header in heap empty file
+ *
+ * @return appened heap header
+ * @throws HeapException
+ *
+ */
+ private RecordForTest appendHeaderInEmptyFile() throws HeapException {
+ heapElementManager.startService();
+ heapElementManager.openTransaction();
+ final RecordForTest heapHeader1 = getHeapHeaderAndCheckPosition(null);
+ assertEquals("bad value", HEAP_HEADER_VALUE, heapHeader1.getValue());
+ assertFalse("created header must be saved",
+ heapHeader1.isValueChangedToSave());
+ heapElementManager.closeTransaction();
+ heapElementManager.stopService();
+ assertFalse("saving implies no more value changed",
+ heapHeader1.isValueChangedToSave());
+ assertFalse("just created must be false", heapHeader1.isJustCreated());
+ return heapHeader1;
+ }
+
+ /**
+ * get heap header and check its position
+ *
+ * @param heapHeaderReference
+ *
+ * @return heap header
+ * @throws HeapException
+ */
+ private RecordForTest getHeapHeaderAndCheckPosition(
+ final RecordForTest heapHeaderReference) throws HeapException {
+ final RecordForTest heapHeader = (RecordForTest) heapElementManager
+ .getHeapHeader();
+ assertEquals("header must be at file beginning", 0,
+ heapHeader.getPositionInFile());
+ if (heapHeaderReference != null) {
+ assertEquals("wrote and read must be equals", heapHeaderReference,
+ heapHeader);
+ }
+ return heapHeader;
+ }
+
+ private void appendRecords() throws HeapException {
+ heapElementManager.openTransaction();
+ for (int recordNumber = 0; recordNumber < 100; recordNumber++) {
+ final RecordForTest heapRecord = new RecordForTest(
+ heapElementManager, RECORD_SIZE * (recordNumber + 1),
+ RECORD_SIZE, RECORD_SIZE * recordNumber);
+ heapRecord.setValue(recordNumber);
+ heapElementManager.appendHeapFileRecord(heapRecord);
+ }
+ heapElementManager.closeTransaction();
+ }
+
+ @Override
+ public IFileStorable createHeapRecord(
+ final HeapElementManager heapElementManager,
+ final long positionInFile) throws HeapException {
+ return new RecordForTest(heapElementManager, positionInFile,
+ RECORD_SIZE, positionInFile - RECORD_SIZE);
+ }
+}
Modified: trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java
===================================================================
--- trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java 2012-04-19 01:10:23 UTC (rev 3019)
+++ trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java 2012-04-19 02:51:34 UTC (rev 3020)
@@ -26,10 +26,7 @@
public static Test suite() {
final TestSuite suite = new TestSuite("Test for kvstore.record.service");
// $JUnit-BEGIN$
- // suite.addTestSuite(TestRandomAccessFileCache.class);
- // suite.addTestSuite(TestHeapElementManager.class);
- // suite.addTestSuite(TestHeapRecordManage.class);
- // suite.addTestSuite(TestStoreRestore.class);
+ suite.addTestSuite(TestHeapElementManager.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-20 01:44:03
|
Revision: 3021
http://joafip.svn.sourceforge.net/joafip/?rev=3021&view=rev
Author: luc_peuvrier
Date: 2012-04-20 01:43:56 +0000 (Fri, 20 Apr 2012)
Log Message:
-----------
data record key moved to joafip-kvstore because of common usage
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/DataRecordKeyManager.java
Added Paths:
-----------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/record/entity/DataRecordKey.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/DataRecordKey.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|