Author: manik.surtani(a)jboss.com
Date: 2009-02-17 13:57:21 -0500 (Tue, 17 Feb 2009)
New Revision: 7713
Added:
core/branches/flat/src/test/java/org/horizon/marshall/ObjectStreamMarshaller.java
Modified:
core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java
core/branches/flat/src/test/java/org/horizon/loader/BaseCacheStoreTest.java
core/branches/flat/src/test/java/org/horizon/loader/decorators/ChainingCacheLoaderTest.java
core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStore.java
Log:
Better dummy loader
Modified: core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java 2009-02-17
18:46:49 UTC (rev 7712)
+++
core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java 2009-02-17
18:57:21 UTC (rev 7713)
@@ -9,15 +9,7 @@
import org.horizon.logging.LogFactory;
import org.horizon.marshall.Marshaller;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
+import java.io.*;
import java.util.Map;
import java.util.Set;
@@ -38,6 +30,8 @@
// TODO: make bucket size fixed rather than number of buckets, and support resizes
private static final int NUM_BUCKETS = Integer.MAX_VALUE;
+ // TODO use read and write locks on buckets!
+
FileCacheStoreConfig cfg;
Cache cache;
Marshaller m;
@@ -87,7 +81,7 @@
}
public Class<? extends CacheLoaderConfig> getConfigurationClass() {
- return null; // TODO: Manik: Customise this generated block
+ return FileCacheStoreConfig.class;
}
public void start() {
@@ -168,4 +162,25 @@
private int index(int h) {
return h & (NUM_BUCKETS - 1);
}
+
+ private Map<Object, StoredEntry> deserialize(Object key, boolean createIfNeeded)
{
+ return null;
+ }
+
+ private void serialize(Map<Object, StoredEntry> map) {
+
+ }
+
+ private static class Bucket implements Externalizable {
+ Map<Object, StoredEntry> entries;
+ String bucketName;
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ // TODO: Manik: Customise this generated block
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
+ // TODO: Manik: Customise this generated block
+ }
+ }
}
Modified: core/branches/flat/src/test/java/org/horizon/loader/BaseCacheStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/BaseCacheStoreTest.java 2009-02-17
18:46:49 UTC (rev 7712)
+++ core/branches/flat/src/test/java/org/horizon/loader/BaseCacheStoreTest.java 2009-02-17
18:57:21 UTC (rev 7713)
@@ -2,12 +2,12 @@
import org.easymock.EasyMock;
import org.horizon.Cache;
-import org.horizon.io.ByteBuffer;
import org.horizon.loader.modifications.Clear;
import org.horizon.loader.modifications.Modification;
import org.horizon.loader.modifications.Remove;
import org.horizon.loader.modifications.Store;
import org.horizon.marshall.Marshaller;
+import org.horizon.marshall.ObjectStreamMarshaller;
import org.horizon.util.Util;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -17,9 +17,6 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -61,48 +58,7 @@
* @return a mock marshaller for use with the cache store impls
*/
protected Marshaller getMarshaller() {
- return new Marshaller() {
-
- public void objectToObjectStream(Object obj, ObjectOutputStream out) throws
IOException {
- out.writeObject(obj);
- }
-
- public Object objectFromObjectStream(ObjectInputStream in) throws IOException,
ClassNotFoundException {
- return in.readObject();
- }
-
- public Object objectFromStream(InputStream is) throws IOException,
ClassNotFoundException {
- if (is instanceof ObjectInputStream)
- return objectFromObjectStream((ObjectInputStream) is);
- else
- return objectFromObjectStream(new ObjectInputStream(is));
- }
-
- public ByteBuffer objectToBuffer(Object o) throws IOException {
- byte[] b = objectToByteBuffer(o);
- return new ByteBuffer(b, 0, b.length);
- }
-
- public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws
IOException, ClassNotFoundException {
- byte[] newBytes = new byte[length];
- System.arraycopy(buf, offset, newBytes, 0, length);
- return objectFromByteBuffer(newBytes);
- }
-
- public byte[] objectToByteBuffer(Object obj) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- objectToObjectStream(obj, oos);
- oos.flush();
- oos.close();
- baos.close();
- return baos.toByteArray();
- }
-
- public Object objectFromByteBuffer(byte[] buf) throws IOException,
ClassNotFoundException {
- return objectFromObjectStream(new ObjectInputStream(new
ByteArrayInputStream(buf)));
- }
- };
+ return new ObjectStreamMarshaller();
}
Modified:
core/branches/flat/src/test/java/org/horizon/loader/decorators/ChainingCacheLoaderTest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/loader/decorators/ChainingCacheLoaderTest.java 2009-02-17
18:46:49 UTC (rev 7712)
+++
core/branches/flat/src/test/java/org/horizon/loader/decorators/ChainingCacheLoaderTest.java 2009-02-17
18:57:21 UTC (rev 7713)
@@ -10,6 +10,7 @@
import org.horizon.loader.modifications.Modification;
import org.horizon.loader.modifications.Remove;
import org.horizon.loader.modifications.Store;
+import org.horizon.marshall.ObjectStreamMarshaller;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -35,12 +36,12 @@
ChainingCacheStore store = new ChainingCacheStore();
CacheLoaderConfig cfg;
store1 = new DummyInMemoryCacheStore();
- store1.init((cfg = new DummyInMemoryCacheStore.Cfg("instance1")), null,
null);
+ store1.init((cfg = new DummyInMemoryCacheStore.Cfg("instance1")), null,
new ObjectStreamMarshaller());
store.addCacheLoader(store1, cfg);
store2 = new DummyInMemoryCacheStore();
- store2.init((cfg = new DummyInMemoryCacheStore.Cfg("instance2")), null,
null);
+ store2.init((cfg = new DummyInMemoryCacheStore.Cfg("instance2")), null,
new ObjectStreamMarshaller());
// set store2 up for streaming
cfg.setFetchPersistentState(true);
store.addCacheLoader(store2, cfg);
@@ -267,5 +268,10 @@
assert !store1.containsKey("k1");
assert !store1.containsKey("k2");
}
+
+ @Override
+ public void testConfigFile() {
+ // no op
+ }
}
Modified:
core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStore.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStore.java 2009-02-17
18:46:49 UTC (rev 7712)
+++
core/branches/flat/src/test/java/org/horizon/loader/dummy/DummyInMemoryCacheStore.java 2009-02-17
18:57:21 UTC (rev 7713)
@@ -8,6 +8,7 @@
import org.horizon.logging.Log;
import org.horizon.logging.LogFactory;
import org.horizon.marshall.Marshaller;
+import org.horizon.marshall.ObjectStreamMarshaller;
import java.io.IOException;
import java.io.InputStream;
@@ -74,6 +75,7 @@
this.config = (Cfg) config;
this.cache = cache;
this.marshaller = m;
+ if (marshaller == null) marshaller = new ObjectStreamMarshaller();
}
public StoredEntry load(Object key) {
Added: core/branches/flat/src/test/java/org/horizon/marshall/ObjectStreamMarshaller.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/marshall/ObjectStreamMarshaller.java
(rev 0)
+++
core/branches/flat/src/test/java/org/horizon/marshall/ObjectStreamMarshaller.java 2009-02-17
18:57:21 UTC (rev 7713)
@@ -0,0 +1,58 @@
+package org.horizon.marshall;
+
+import org.horizon.io.ByteBuffer;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * A dummy marshaller impl that uses JDK object streams
+ *
+ * @author Manik Surtani
+ */
+public class ObjectStreamMarshaller implements Marshaller {
+ public void objectToObjectStream(Object obj, ObjectOutputStream out) throws
IOException {
+ out.writeObject(obj);
+ }
+
+ public Object objectFromObjectStream(ObjectInputStream in) throws IOException,
ClassNotFoundException {
+ return in.readObject();
+ }
+
+ public Object objectFromStream(InputStream is) throws IOException,
ClassNotFoundException {
+ if (is instanceof ObjectInputStream)
+ return objectFromObjectStream((ObjectInputStream) is);
+ else
+ return objectFromObjectStream(new ObjectInputStream(is));
+ }
+
+ public ByteBuffer objectToBuffer(Object o) throws IOException {
+ byte[] b = objectToByteBuffer(o);
+ return new ByteBuffer(b, 0, b.length);
+ }
+
+ public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws
IOException, ClassNotFoundException {
+ byte[] newBytes = new byte[length];
+ System.arraycopy(buf, offset, newBytes, 0, length);
+ return objectFromByteBuffer(newBytes);
+ }
+
+ public byte[] objectToByteBuffer(Object obj) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ objectToObjectStream(obj, oos);
+ oos.flush();
+ oos.close();
+ baos.close();
+ return baos.toByteArray();
+ }
+
+ public Object objectFromByteBuffer(byte[] buf) throws IOException,
ClassNotFoundException {
+ return objectFromObjectStream(new ObjectInputStream(new
ByteArrayInputStream(buf)));
+ }
+
+}