Author: vgritsenko
Date: Thu Mar 15 20:35:49 2007
New Revision: 518852
URL: http://svn.apache.org/viewvc?view=rev&rev=518852
Log:
clean up unused file header constructors, and other cleanup
Removed:
xml/xindice/trunk/java/tests/src/org/apache/xindice/stress/
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java
xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java
xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java
xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java
xml/xindice/trunk/java/tests/src/org/apache/xindice/StressTests.java
xml/xindice/trunk/java/tests/src/org/apache/xindice/UnitTests.java
xml/xindice/trunk/java/tests/src/org/apache/xindice/core/filer/FilerTestBase.java
xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java?view=diff&rev=518852&r1=518851&r2=518852
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTree.java Thu Mar 15 20:35:49 2007
@@ -969,23 +969,11 @@
////////////////////////////////////////////////////////////////////
- public FileHeader createFileHeader() {
+ protected FileHeader createFileHeader() {
return new BTreeFileHeader();
}
- public FileHeader createFileHeader(boolean read) throws IOException {
- return new BTreeFileHeader(read);
- }
-
- public FileHeader createFileHeader(long pageCount) {
- return new BTreeFileHeader(pageCount);
- }
-
- public FileHeader createFileHeader(long pageCount, int pageSize) {
- return new BTreeFileHeader(pageCount, pageSize);
- }
-
- public PageHeader createPageHeader() {
+ protected PageHeader createPageHeader() {
return new BTreePageHeader();
}
@@ -994,29 +982,17 @@
*/
protected class BTreeFileHeader extends FileHeader {
- private long rootPage = 0;
+ private long rootPage;
public BTreeFileHeader() {
}
- public BTreeFileHeader(long pageCount) {
- super(pageCount);
- }
-
- public BTreeFileHeader(long pageCount, int pageSize) {
- super(pageCount, pageSize);
- }
-
- public BTreeFileHeader(boolean read) throws IOException {
- super(read);
- }
-
- public synchronized void read(RandomAccessFile raf) throws IOException {
+ protected synchronized void read(RandomAccessFile raf) throws IOException {
super.read(raf);
rootPage = raf.readLong();
}
- public synchronized void write(RandomAccessFile raf) throws IOException {
+ protected synchronized void write(RandomAccessFile raf) throws IOException {
super.write(raf);
raf.writeLong(rootPage);
}
@@ -1038,7 +1014,7 @@
*/
protected class BTreePageHeader extends PageHeader {
- private short valueCount = 0;
+ private short valueCount;
public BTreePageHeader() {
}
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java?view=diff&rev=518852&r1=518851&r2=518852
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/BTreeFiler.java Thu Mar 15 20:35:49 2007
@@ -236,54 +236,29 @@
////////////////////////////////////////////////////////////////////
- public FileHeader createFileHeader() {
+ protected FileHeader createFileHeader() {
return new BTreeFilerHeader();
}
- public FileHeader createFileHeader(boolean read) throws IOException {
- return new BTreeFilerHeader(read);
- }
-
- public FileHeader createFileHeader(long pageCount) {
- return new BTreeFilerHeader(pageCount);
- }
-
- public FileHeader createFileHeader(long pageCount, int pageSize) {
- return new BTreeFilerHeader(pageCount, pageSize);
- }
-
- public PageHeader createPageHeader() {
+ protected PageHeader createPageHeader() {
return new BTreeFilerPageHeader();
}
/**
* BTreeFilerHeader
*/
-
private final class BTreeFilerHeader extends BTreeFileHeader {
- private long totalBytes = 0;
+ private long totalBytes;
public BTreeFilerHeader() {
}
- public BTreeFilerHeader(long pageCount) {
- super(pageCount);
- }
-
- public BTreeFilerHeader(long pageCount, int pageSize) {
- super(pageCount, pageSize);
- }
-
- public BTreeFilerHeader(boolean read) throws IOException {
- super(read);
- }
-
- public synchronized void read(RandomAccessFile raf) throws IOException {
+ protected synchronized void read(RandomAccessFile raf) throws IOException {
super.read(raf);
totalBytes = raf.readLong();
}
- public synchronized void write(RandomAccessFile raf) throws IOException {
+ protected synchronized void write(RandomAccessFile raf) throws IOException {
super.write(raf);
raf.writeLong(totalBytes);
}
@@ -303,10 +278,9 @@
/**
* BTreeFilerPageHeader
*/
-
private final class BTreeFilerPageHeader extends BTreePageHeader {
- private long created = 0;
- private long modified = 0;
+ private long created;
+ private long modified;
public BTreeFilerPageHeader() {
}
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java?view=diff&rev=518852&r1=518851&r2=518852
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/HashFiler.java Thu Mar 15 20:35:49 2007
@@ -383,18 +383,6 @@
return new HashFileHeader();
}
- public FileHeader createFileHeader(boolean read) throws IOException {
- return new HashFileHeader(read);
- }
-
- public FileHeader createFileHeader(long pageCount) {
- return new HashFileHeader(pageCount);
- }
-
- public FileHeader createFileHeader(long pageCount, int pageSize) {
- return new HashFileHeader(pageCount, pageSize);
- }
-
public PageHeader createPageHeader() {
return new HashPageHeader();
}
@@ -411,27 +399,12 @@
setTotalCount(getPageCount());
}
- public HashFileHeader(long pageCount) {
- super(pageCount);
- setTotalCount(getPageCount());
- }
-
- public HashFileHeader(long pageCount, int pageSize) {
- super(pageCount, pageSize);
- setTotalCount(getPageCount());
- }
-
- public HashFileHeader(boolean read) throws IOException {
- super(read);
- setTotalCount(getPageCount());
- }
-
- public synchronized void read(RandomAccessFile raf) throws IOException {
+ protected synchronized void read(RandomAccessFile raf) throws IOException {
super.read(raf);
totalBytes = raf.readLong();
}
- public synchronized void write(RandomAccessFile raf) throws IOException {
+ protected synchronized void write(RandomAccessFile raf) throws IOException {
super.write(raf);
raf.writeLong(totalBytes);
}
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java?view=diff&rev=518852&r1=518851&r2=518852
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java Thu Mar 15 20:35:49 2007
@@ -333,21 +333,15 @@
*/
protected final Page getPage(long pageNum) throws IOException {
final Long lp = new Long(pageNum);
- Page p;
- synchronized (this) {
- // Check if it's in the dirty cache
- // No need to synchronize on dirtyLock thanks to atomic assignment
- p = (Page) dirty.get(lp);
-
- // if not check if it's already loaded in the page cache
- if (p == null) {
- WeakReference ref = (WeakReference) pages.get(lp);
- if (ref != null) {
- p = (Page) ref.get();
- }
+ Page p = null;
+ synchronized (pages) {
+ // Check if page is already loaded in the page cache
+ WeakReference ref = (WeakReference) pages.get(lp);
+ if (ref != null) {
+ p = (Page) ref.get();
}
- // if still not found we need to create it and add it to the page cache.
+ // If not found, create it and add it to the page cache
if (p == null) {
p = new Page(lp);
pages.put(p.pageNum, new WeakReference(p));
@@ -680,15 +674,18 @@
}
void addDirty(Page page) throws IOException {
+ boolean flush;
synchronized (dirtyLock) {
dirty.put(page.pageNum, page);
- if (dirty.size() > MAX_DIRTY_SIZE) {
- try {
- // Too many dirty pages... flush them
- flush();
- } catch (Exception e) {
- throw new IOException(e.getMessage());
- }
+ flush = dirty.size() > MAX_DIRTY_SIZE;
+ }
+
+ if (flush) {
+ // Too many dirty pages... flush them
+ try {
+ flush();
+ } catch (Exception e) {
+ throw new IOException(e.getMessage());
}
}
}
@@ -713,7 +710,7 @@
try {
p.flush();
} catch (Exception e) {
- log.warn("Exception while flushing page", e);
+ log.warn("Exception while flushing page " + p.pageNum, e);
error++;
}
}
@@ -741,36 +738,7 @@
*
* @return a new FileHeader
*/
- public abstract FileHeader createFileHeader();
-
- /**
- * createFileHeader must be implemented by a Paged implementation
- * in order to create an appropriate subclass instance of a FileHeader.
- *
- * @param read If true, reads the FileHeader from disk
- * @return a new FileHeader
- * @throws IOException if an exception occurs
- */
- public abstract FileHeader createFileHeader(boolean read) throws IOException;
-
- /**
- * createFileHeader must be implemented by a Paged implementation
- * in order to create an appropriate subclass instance of a FileHeader.
- *
- * @param pageCount The number of pages to allocate for primary storage
- * @return a new FileHeader
- */
- public abstract FileHeader createFileHeader(long pageCount);
-
- /**
- * createFileHeader must be implemented by a Paged implementation
- * in order to create an appropriate subclass instance of a FileHeader.
- *
- * @param pageCount The number of pages to allocate for primary storage
- * @param pageSize The size of a Page (should be a multiple of a FS block)
- * @return a new FileHeader
- */
- public abstract FileHeader createFileHeader(long pageCount, int pageSize);
+ protected abstract FileHeader createFileHeader();
/**
* createPageHeader must be implemented by a Paged implementation
@@ -778,7 +746,7 @@
*
* @return a new PageHeader
*/
- public abstract PageHeader createPageHeader();
+ protected abstract PageHeader createPageHeader();
// These are a bunch of utility methods for subclasses
@@ -912,30 +880,15 @@
public FileHeader() {
- this(DEFAULT_PAGECOUNT);
- }
-
- public FileHeader(long pageCount) {
- this(pageCount, DEFAULT_PAGESIZE);
- }
-
- public FileHeader(long pageCount, int pageSize) {
- this.pageSize = pageSize;
- this.pageCount = pageCount;
+ this.pageSize = DEFAULT_PAGESIZE;
+ this.pageCount = DEFAULT_PAGECOUNT;
this.headerSize = (short) FILE_HEADER_SIZE;
calculateWorkSize();
}
- public FileHeader(boolean read) throws IOException {
- if (read) {
- read();
- }
- }
-
public synchronized final void read() throws IOException {
- RandomAccessFile raf = null;
+ RandomAccessFile raf = getDescriptor();
try {
- raf = getDescriptor();
raf.seek(0);
read(raf);
calculateWorkSize();
@@ -944,7 +897,7 @@
}
}
- public synchronized void read(RandomAccessFile raf) throws IOException {
+ protected synchronized void read(RandomAccessFile raf) throws IOException {
headerSize = raf.readShort();
pageSize = raf.readInt();
pageCount = raf.readLong();
@@ -957,22 +910,19 @@
}
public synchronized final void write() throws IOException {
- if (!dirty) {
- return;
- }
-
- RandomAccessFile raf = null;
- try {
- raf = getDescriptor();
- raf.seek(0);
- write(raf);
- dirty = false;
- } finally {
- putDescriptor(raf);
+ if (dirty) {
+ RandomAccessFile raf = getDescriptor();
+ try {
+ raf.seek(0);
+ write(raf);
+ dirty = false;
+ } finally {
+ putDescriptor(raf);
+ }
}
}
- public synchronized void write(RandomAccessFile raf) throws IOException {
+ protected synchronized void write(RandomAccessFile raf) throws IOException {
raf.writeShort(headerSize);
raf.writeInt(pageSize);
raf.writeLong(pageCount);
@@ -1089,8 +1039,6 @@
/**
* Get the size of a page header.
- *
- * Normally, 64 is sufficient
*/
public synchronized final byte getPageHeaderSize() {
return pageHeaderSize;
@@ -1107,9 +1055,7 @@
}
/**
- * Get the maximum number of bytes.
- *
- * Normally, 256 is good.
+ * Get the maximum number of bytes a key can be.
*/
public synchronized final short getMaxKeySize() {
return maxKeySize;
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java?view=diff&rev=518852&r1=518851&r2=518852
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java Thu Mar 15 20:35:49 2007
@@ -87,7 +87,7 @@
private String pattern;
private int type;
private int typeSize = 32;
- private boolean wildcard = false;
+ private boolean wildcard;
public ValueIndexer() {
@@ -97,7 +97,7 @@
/**
* Override createFileHeader - set page size to 1024
*/
- public Paged.FileHeader createFileHeader() {
+ protected Paged.FileHeader createFileHeader() {
Paged.FileHeader header = super.createFileHeader();
header.setPageSize(1024);
return header;
@@ -268,7 +268,7 @@
case CHAR:
char c = value.charAt(0);
b[0] = (byte) ((c >>> 8) & 0xFF);
- b[1] = (byte) ((c >>> 0) & 0xFF);
+ b[1] = (byte) ( c & 0xFF);
break;
case BOOLEAN:
@@ -315,21 +315,21 @@
b[l + 1] = (byte) ((pos >>> 24) & 0xFF);
b[l + 2] = (byte) ((pos >>> 16) & 0xFF);
b[l + 3] = (byte) ((pos >>> 8) & 0xFF);
- b[l + 4] = (byte) ((pos >>> 0) & 0xFF);
+ b[l + 4] = (byte) ( pos & 0xFF);
// Write the len
b[l + 5] = (byte) ((len >>> 24) & 0xFF);
b[l + 6] = (byte) ((len >>> 16) & 0xFF);
b[l + 7] = (byte) ((len >>> 8) & 0xFF);
- b[l + 8] = (byte) ((len >>> 0) & 0xFF);
+ b[l + 8] = (byte) ( len & 0xFF);
// Write the elemID
b[l + 9] = (byte) ((elemID >>> 8) & 0xFF);
- b[l + 10] = (byte) ((elemID >>> 0) & 0xFF);
+ b[l + 10] = (byte) ( elemID & 0xFF);
// Write the attrID
b[l + 11] = (byte) ((attrID >>> 8) & 0xFF);
- b[l + 12] = (byte) ((attrID >>> 0) & 0xFF);
+ b[l + 12] = (byte) ( attrID & 0xFF);
result = new Value(b);
} catch (Exception e) {
Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/StressTests.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/StressTests.java?view=diff&rev=518852&r1=518851&r2=518852
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/StressTests.java (original)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/StressTests.java Thu Mar 15 20:35:49 2007
@@ -19,24 +19,32 @@
package org.apache.xindice;
+import org.apache.xindice.core.filer.HashFilerTest;
+
+import com.clarkware.junitperf.LoadTest;
import junit.framework.Test;
import junit.framework.TestSuite;
+import junit.framework.TestCase;
/**
* @version $Revision$, $Date$
* @author Vladimir R. Bossicard <[email protected]>
*/
-public class StressTests {
+public class StressTests extends TestSuite {
+
+ private static final int USERS = 5;
+ private static final int ITERATIONS = 5;
- private static final int USERS = 1;
- private static final int ITERATIONS = 1;
+ public StressTests(String name) {
+ super(name);
+ }
- public static Test suite() {
- TestSuite suite = new TestSuite("Xindice stress tests");
+ public static Test suite() {
+ TestSuite suite = new StressTests("Xindice stress tests");
// suite.addTest(new StressFilerTestSetup(new TestSuite(FilerTestCase.class), new BTreeFiler(), USERS, ITERATIONS));
// suite.addTest(new StressFilerTestSetup(new TestSuite(FilerTestCase.class), new FSFiler(), USERS, ITERATIONS));
-// suite.addTest(new StressFilerTestSetup(new TestSuite(FilerTestCase.class), new HashFiler(), USERS, ITERATIONS));
+// suite.addTest(new LoadTest(new TestSuite(HashFilerTest.class), USERS, ITERATIONS));
// suite.addTest(new StressFilerTestSetup(new TestSuite(FilerTestCase.class), new MemFiler(), USERS, ITERATIONS));
return suite;
Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/UnitTests.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/UnitTests.java?view=diff&rev=518852&r1=518851&r2=518852
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/UnitTests.java (original)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/UnitTests.java Thu Mar 15 20:35:49 2007
@@ -44,7 +44,7 @@
try {
Class filerClass = Class.forName("org.apache.xindice.core.filer.BerkeleyBTreeFiler");
Filer filer = (Filer) filerClass.newInstance();
- suite.addTest(new FilerTestBase("BerkeleyFilerTestCase", filer));
+ suite.addTest(new FilerTestBase("BerkeleyFilerTestCase", filer){});
} catch (Exception e) {
// If the class wasn't built just ignore it.
}
Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/core/filer/FilerTestBase.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/core/filer/FilerTestBase.java?view=diff&rev=518852&r1=518851&r2=518852
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/core/filer/FilerTestBase.java (original)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/core/filer/FilerTestBase.java Thu Mar 15 20:35:49 2007
@@ -40,7 +40,7 @@
* @author <a href="mailto:[email protected]">Vladimir R. Bossicard</a>
* @author <a href="mailto:[email protected]">Vadim Gritsenko</a>
*/
-public class FilerTestBase extends TestCase {
+public abstract class FilerTestBase extends TestCase {
public static final String TEST_COLLECTION_NAME = "tests";
public static final Key TEST_KEY = new Key("test.xml");
Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java?view=diff&rev=518852&r1=518851&r2=518852
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java (original)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java Thu Mar 15 20:35:49 2007
@@ -89,8 +89,8 @@
}
public void testCommonEntities() {
- Node n = root.getFirstChild().getFirstChild().getFirstChild();
- assertEquals("<common & entities>", n.getNodeValue());
+ Node n = root.getFirstChild().getFirstChild();
+ assertEquals("<common & entities>", ((NodeImpl) n).getTextContent());
}
public void testCDATA() {
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.