[infinispan-commits] Infinispan SVN: r142 - in trunk/cachestore: s3/src/main/java/org/infinispan/loader/s3 and 1 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Fri Apr 17 12:12:34 EDT 2009
Author: manik.surtani at jboss.com
Date: 2009-04-17 11:47:20 -0400 (Fri, 17 Apr 2009)
New Revision: 142
Modified:
trunk/cachestore/jdbc/src/test/java/org/infinispan/loader/jdbc/stringbased/JdbcStringBasedCacheStoreTest2.java
trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/S3CacheStore.java
trunk/cachestore/s3/src/test/java/org/infinispan/loader/s3/S3CacheStoreIntegrationTest.java
Log:
compiler warnings
Modified: trunk/cachestore/jdbc/src/test/java/org/infinispan/loader/jdbc/stringbased/JdbcStringBasedCacheStoreTest2.java
===================================================================
--- trunk/cachestore/jdbc/src/test/java/org/infinispan/loader/jdbc/stringbased/JdbcStringBasedCacheStoreTest2.java 2009-04-17 15:44:19 UTC (rev 141)
+++ trunk/cachestore/jdbc/src/test/java/org/infinispan/loader/jdbc/stringbased/JdbcStringBasedCacheStoreTest2.java 2009-04-17 15:47:20 UTC (rev 142)
@@ -91,11 +91,11 @@
cacheStore.store(InternalEntryFactory.create(MANIK, "value"));
assert rowCount() == 2;
cacheStore.removeAll(Collections.singleton((Object) MIRCEA));
- cacheStore.load(MANIK).getValue().equals("value");
+ assert cacheStore.load(MANIK).getValue().equals("value");
assert rowCount() == 1;
cacheStore.store(InternalEntryFactory.create(MIRCEA, "value"));
assert rowCount() == 2;
- Set toRemove = new HashSet();
+ Set<Object> toRemove = new HashSet<Object>();
toRemove.add(MIRCEA);
toRemove.add(MANIK);
cacheStore.removeAll(toRemove);
Modified: trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/S3CacheStore.java
===================================================================
--- trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/S3CacheStore.java 2009-04-17 15:44:19 UTC (rev 141)
+++ trunk/cachestore/s3/src/main/java/org/infinispan/loader/s3/S3CacheStore.java 2009-04-17 15:47:20 UTC (rev 142)
@@ -17,8 +17,8 @@
import java.util.Set;
/**
- * A TODO link implementation of a {@link org.infinispan.loader.bucket.BucketBasedCacheStore}.
- * This file store stores stuff in the following format: <tt>http://s3.amazon.com/{bucket}/bucket_number.bucket</tt>
+ * A TODO link implementation of a {@link org.infinispan.loader.bucket.BucketBasedCacheStore}. This file store stores
+ * stuff in the following format: <tt>http://s3.amazon.com/{bucket}/bucket_number.bucket</tt>
* <p/>
*
* @author Adrian Cole
@@ -26,118 +26,119 @@
*/
public class S3CacheStore extends BucketBasedCacheStore {
- private static final Log log = LogFactory.getLog(S3CacheStore.class);
+ private static final Log log = LogFactory.getLog(S3CacheStore.class);
- private S3CacheStoreConfig config;
+ private S3CacheStoreConfig config;
- Cache cache;
- Marshaller marshaller;
+ Cache cache;
+ Marshaller marshaller;
- private S3Connection connection;
- private S3Bucket s3Bucket;
+ private S3Connection connection;
+ private S3Bucket s3Bucket;
- public Class<? extends CacheLoaderConfig> getConfigurationClass() {
- return S3CacheStoreConfig.class;
- }
+ public Class<? extends CacheLoaderConfig> getConfigurationClass() {
+ return S3CacheStoreConfig.class;
+ }
- /**
- * {@inheritDoc} This initializes the internal <tt>s3Connection</tt> to a default implementation
- */
- public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
- throw new UnsupportedOperationException("no default implementation, yet");
+ /**
+ * {@inheritDoc} This initializes the internal <tt>s3Connection</tt> to a default implementation
+ */
+ public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
+ throw new UnsupportedOperationException("no default implementation, yet");
// init(config, cache, m, null, null);
- }
+ }
- @Override
- public void stop() throws CacheLoaderException {
- super.stop();
- this.connection.disconnect();
- }
+ @Override
+ public void stop() throws CacheLoaderException {
+ super.stop();
+ this.connection.disconnect();
+ }
- public void init(CacheLoaderConfig config, Cache cache, Marshaller m, S3Connection connection, S3Bucket bucket) {
- super.init(config, cache, m);
- this.config = (S3CacheStoreConfig) config;
- this.cache = cache;
- this.marshaller = m;
- this.connection = connection;
- this.s3Bucket = bucket;
- }
+ public void init(CacheLoaderConfig config, Cache cache, Marshaller m, S3Connection connection, S3Bucket bucket) {
+ super.init(config, cache, m);
+ this.config = (S3CacheStoreConfig) config;
+ this.cache = cache;
+ this.marshaller = m;
+ this.connection = connection;
+ this.s3Bucket = bucket;
+ }
- public void start() throws CacheLoaderException {
- super.start();
+ @SuppressWarnings("unchecked")
+ @Override
+ public void start() throws CacheLoaderException {
+ super.start();
- if (config.getAwsAccessKey() == null)
- throw new IllegalArgumentException("awsAccessKey must be set");
- if (config.getAwsSecretKey() == null)
- throw new IllegalArgumentException("awsSecretKey must be set");
- this.connection.connect(config, marshaller);
- String s3Bucket = config.getBucket();
- if (s3Bucket == null)
- throw new IllegalArgumentException("s3Bucket must be set");
- this.s3Bucket.init(this.connection, connection.verifyOrCreateBucket(s3Bucket));
- }
+ if (config.getAwsAccessKey() == null)
+ throw new IllegalArgumentException("awsAccessKey must be set");
+ if (config.getAwsSecretKey() == null)
+ throw new IllegalArgumentException("awsSecretKey must be set");
+ this.connection.connect(config, marshaller);
+ String s3Bucket = config.getBucket();
+ if (s3Bucket == null)
+ throw new IllegalArgumentException("s3Bucket must be set");
+ this.s3Bucket.init(this.connection, connection.verifyOrCreateBucket(s3Bucket));
+ }
- protected Set<InternalCacheEntry> loadAllLockSafe() throws CacheLoaderException {
- Set<InternalCacheEntry> result = new HashSet<InternalCacheEntry>();
- // TODO I don't know why this returns objects at the moment
- for (Bucket bucket : (Set<Bucket>) s3Bucket.values()) {
- if (bucket.removeExpiredEntries()) {
- saveBucket(bucket);
- }
- result.addAll(bucket.getStoredEntries());
- }
- return result;
- }
+ @SuppressWarnings("unchecked")
+ protected Set<InternalCacheEntry> loadAllLockSafe() throws CacheLoaderException {
+ Set<InternalCacheEntry> result = new HashSet<InternalCacheEntry>();
+ // TODO I don't know why this returns objects at the moment
+ for (Bucket bucket : (Set<Bucket>) s3Bucket.values()) {
+ if (bucket.removeExpiredEntries()) {
+ saveBucket(bucket);
+ }
+ result.addAll(bucket.getStoredEntries());
+ }
+ return result;
+ }
- protected void fromStreamLockSafe(ObjectInput objectInput) throws CacheLoaderException {
- String source;
- try {
- source = (String) objectInput.readObject();
+ protected void fromStreamLockSafe(ObjectInput objectInput) throws CacheLoaderException {
+ String source;
+ try {
+ source = (String) objectInput.readObject();
- } catch (Exception e) {
- throw convertToCacheLoaderException("Error while reading from stream", e);
- }
- if (config.getBucket().equals(source)) {
- log.info("Attempt to load the same s3 bucket ignored");
- } else {
- connection.copyBucket(source, config.getBucket());
- }
- }
+ } catch (Exception e) {
+ throw convertToCacheLoaderException("Error while reading from stream", e);
+ }
+ if (config.getBucket().equals(source)) {
+ log.info("Attempt to load the same s3 bucket ignored");
+ } else {
+ connection.copyBucket(source, config.getBucket());
+ }
+ }
- protected void toStreamLockSafe(ObjectOutput objectOutput) throws CacheLoaderException {
- try {
- objectOutput.writeObject(config.getBucket());
- } catch (IOException e) {
- throw convertToCacheLoaderException("Error while writing to stream", e);
- }
- }
+ protected void toStreamLockSafe(ObjectOutput objectOutput) throws CacheLoaderException {
+ try {
+ objectOutput.writeObject(config.getBucket());
+ } catch (IOException e) {
+ throw convertToCacheLoaderException("Error while writing to stream", e);
+ }
+ }
- protected void clearLockSafe() throws CacheLoaderException {
- s3Bucket.clear();
- }
+ protected void clearLockSafe() throws CacheLoaderException {
+ s3Bucket.clear();
+ }
- CacheLoaderException convertToCacheLoaderException(String message, Exception caught) {
- return (caught instanceof CacheLoaderException) ? (CacheLoaderException) caught :
- new CacheLoaderException(message, caught);
- }
+ CacheLoaderException convertToCacheLoaderException(String message, Exception caught) {
+ return (caught instanceof CacheLoaderException) ? (CacheLoaderException) caught :
+ new CacheLoaderException(message, caught);
+ }
- protected void purgeInternal() throws CacheLoaderException {
- loadAll();
- }
+ protected void purgeInternal() throws CacheLoaderException {
+ loadAll();
+ }
- protected Bucket loadBucket(String bucketName) throws CacheLoaderException {
- return s3Bucket.get(bucketName);
- }
+ protected Bucket loadBucket(String bucketName) throws CacheLoaderException {
+ return s3Bucket.get(bucketName);
+ }
- protected void insertBucket(Bucket bucket) throws CacheLoaderException {
- s3Bucket.insert(bucket);
- }
+ protected void insertBucket(Bucket bucket) throws CacheLoaderException {
+ s3Bucket.insert(bucket);
+ }
- protected void saveBucket(Bucket bucket) throws CacheLoaderException {
- s3Bucket.insert(bucket);
- }
-
-
+ protected void saveBucket(Bucket bucket) throws CacheLoaderException {
+ s3Bucket.insert(bucket);
+ }
}
Modified: trunk/cachestore/s3/src/test/java/org/infinispan/loader/s3/S3CacheStoreIntegrationTest.java
===================================================================
--- trunk/cachestore/s3/src/test/java/org/infinispan/loader/s3/S3CacheStoreIntegrationTest.java 2009-04-17 15:44:19 UTC (rev 141)
+++ trunk/cachestore/s3/src/test/java/org/infinispan/loader/s3/S3CacheStoreIntegrationTest.java 2009-04-17 15:47:20 UTC (rev 142)
@@ -12,7 +12,11 @@
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.util.HashSet;
import java.util.Set;
@@ -23,152 +27,152 @@
*/
@Test(groups = "unit", enabled = true, sequential = true, testName = "loader.s3.S3CacheStoreIntegrationTest")
public class S3CacheStoreIntegrationTest extends BaseCacheStoreTest {
- private String proxyHost;
- private int proxyPort = -1;
- private int maxConnections = 20;
- private boolean isSecure = false;
- private Class<? extends S3Connection> connectionClass;
- private Class<? extends S3Bucket> bucketClass;
- private String csBucket;
- private String cs2Bucket;
- private String accessKey;
- private String secretKey;
+ private String proxyHost;
+ private int proxyPort = -1;
+ private int maxConnections = 20;
+ private boolean isSecure = false;
+ private Class<? extends S3Connection> connectionClass;
+ private Class<? extends S3Bucket> bucketClass;
+ private String csBucket;
+ private String cs2Bucket;
+ private String accessKey;
+ private String secretKey;
- @BeforeTest(enabled = true)
- public void initMockConnection() {
- csBucket = "infinispantesting";
- cs2Bucket = csBucket + "2";
- accessKey = "dummyaccess";
- secretKey = "dummysecret";
- connectionClass = MockS3Connection.class;
- bucketClass = MockS3Bucket.class;
- }
+ @BeforeTest(enabled = true)
+ public void initMockConnection() {
+ csBucket = "infinispantesting";
+ cs2Bucket = csBucket + "2";
+ accessKey = "dummyaccess";
+ secretKey = "dummysecret";
+ connectionClass = MockS3Connection.class;
+ bucketClass = MockS3Bucket.class;
+ }
- protected CacheStore createCacheStore() throws Exception {
- return createAndStartCacheStore(csBucket);
- }
+ protected CacheStore createCacheStore() throws Exception {
+ return createAndStartCacheStore(csBucket);
+ }
- protected CacheStore createAnotherCacheStore() throws Exception {
- return createAndStartCacheStore(cs2Bucket);
- }
+ protected CacheStore createAnotherCacheStore() throws Exception {
+ return createAndStartCacheStore(cs2Bucket);
+ }
- private CacheStore createAndStartCacheStore(String bucket) throws Exception {
- S3CacheStore cs = new S3CacheStore();
- S3CacheStoreConfig cfg = new S3CacheStoreConfig();
- cfg.setBucket(bucket);
- cfg.setAwsAccessKey(accessKey);
- cfg.setAwsSecretKey(secretKey);
- cfg.setProxyHost(proxyHost);
- cfg.setProxyPort(proxyPort);
- cfg.setSecure(isSecure);
- cfg.setMaxConnections(maxConnections);
- cfg.setPurgeSynchronously(true); // for more accurate unit testing
- cs.init(cfg, getCache(), getMarshaller(), connectionClass.newInstance(), bucketClass.newInstance());
- cs.start();
- return cs;
- }
+ private CacheStore createAndStartCacheStore(String bucket) throws Exception {
+ S3CacheStore cs = new S3CacheStore();
+ S3CacheStoreConfig cfg = new S3CacheStoreConfig();
+ cfg.setBucket(bucket);
+ cfg.setAwsAccessKey(accessKey);
+ cfg.setAwsSecretKey(secretKey);
+ cfg.setProxyHost(proxyHost);
+ cfg.setProxyPort(proxyPort);
+ cfg.setSecure(isSecure);
+ cfg.setMaxConnections(maxConnections);
+ cfg.setPurgeSynchronously(true); // for more accurate unit testing
+ cs.init(cfg, getCache(), getMarshaller(), connectionClass.newInstance(), bucketClass.newInstance());
+ cs.start();
+ return cs;
+ }
- /* Changes below are needed to support testing of multiple cache stores */
+ /* Changes below are needed to support testing of multiple cache stores */
- protected CacheStore cs2;
+ protected CacheStore cs2;
- @BeforeMethod
- @Override
- public void setUp() throws Exception {
- super.setUp();
- cs.clear();
- Set entries = cs.loadAll();
- assert entries.size() == 0;
- cs2 = createAnotherCacheStore();
- cs2.clear();
- entries = cs2.loadAll();
- assert entries.size() == 0;
- }
+ @BeforeMethod
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ cs.clear();
+ Set entries = cs.loadAll();
+ assert entries.size() == 0;
+ cs2 = createAnotherCacheStore();
+ cs2.clear();
+ entries = cs2.loadAll();
+ assert entries.size() == 0;
+ }
- @AfterMethod
- @Override
- public void tearDown() throws CacheLoaderException {
- if (cs != null) {
- cs.clear();
- cs.stop();
+ @AfterMethod
+ @Override
+ public void tearDown() throws CacheLoaderException {
+ if (cs != null) {
+ cs.clear();
+ cs.stop();
- }
- cs = null;
- if (cs2 != null) {
- cs2.clear();
+ }
+ cs = null;
+ if (cs2 != null) {
+ cs2.clear();
- cs2.stop();
- }
- cs2 = null;
- }
+ cs2.stop();
+ }
+ cs2 = null;
+ }
- @Override
- @Test
- public void testStreamingAPI() throws IOException, ClassNotFoundException, CacheLoaderException {
- cs.store(InternalEntryFactory.create("k1", "v1", -1, -1));
- cs.store(InternalEntryFactory.create("k2", "v2", -1, -1));
- cs.store(InternalEntryFactory.create("k3", "v3", -1, -1));
+ @SuppressWarnings("unchecked")
+ @Override
+ public void testStreamingAPI() throws IOException, ClassNotFoundException, CacheLoaderException {
+ cs.store(InternalEntryFactory.create("k1", "v1", -1, -1));
+ cs.store(InternalEntryFactory.create("k2", "v2", -1, -1));
+ cs.store(InternalEntryFactory.create("k3", "v3", -1, -1));
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(out);
- cs.toStream(new UnclosableObjectOutputStream(oos));
- oos.flush();
- oos.close();
- out.close();
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
- cs2.fromStream(new UnclosableObjectInputStream(ois));
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(out);
+ cs.toStream(new UnclosableObjectOutputStream(oos));
+ oos.flush();
+ oos.close();
+ out.close();
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
+ cs2.fromStream(new UnclosableObjectInputStream(ois));
- Set<InternalCacheEntry> set = cs2.loadAll();
+ Set<InternalCacheEntry> set = cs2.loadAll();
- assert set.size() == 3;
- Set expected = new HashSet();
- expected.add("k1");
- expected.add("k2");
- expected.add("k3");
- for (InternalCacheEntry se : set) assert expected.remove(se.getKey());
- assert expected.isEmpty();
- }
+ assert set.size() == 3;
+ Set expected = new HashSet();
+ expected.add("k1");
+ expected.add("k2");
+ expected.add("k3");
+ for (InternalCacheEntry se : set) assert expected.remove(se.getKey());
+ assert expected.isEmpty();
+ }
- @Override
- @Test
- public void testStreamingAPIReusingStreams() throws IOException, ClassNotFoundException, CacheLoaderException {
- cs.store(InternalEntryFactory.create("k1", "v1", -1, -1));
- cs.store(InternalEntryFactory.create("k2", "v2", -1, -1));
- cs.store(InternalEntryFactory.create("k3", "v3", -1, -1));
+ @SuppressWarnings("unchecked")
+ @Override
+ public void testStreamingAPIReusingStreams() throws IOException, ClassNotFoundException, CacheLoaderException {
+ cs.store(InternalEntryFactory.create("k1", "v1", -1, -1));
+ cs.store(InternalEntryFactory.create("k2", "v2", -1, -1));
+ cs.store(InternalEntryFactory.create("k3", "v3", -1, -1));
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- byte[] dummyStartBytes = {1, 2, 3, 4, 5, 6, 7, 8};
- byte[] dummyEndBytes = {8, 7, 6, 5, 4, 3, 2, 1};
- out.write(dummyStartBytes);
- ObjectOutputStream oos = new ObjectOutputStream(out);
- cs.toStream(new UnclosableObjectOutputStream(oos));
- oos.flush();
- oos.close();
- out.write(dummyEndBytes);
- out.close();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] dummyStartBytes = {1, 2, 3, 4, 5, 6, 7, 8};
+ byte[] dummyEndBytes = {8, 7, 6, 5, 4, 3, 2, 1};
+ out.write(dummyStartBytes);
+ ObjectOutputStream oos = new ObjectOutputStream(out);
+ cs.toStream(new UnclosableObjectOutputStream(oos));
+ oos.flush();
+ oos.close();
+ out.write(dummyEndBytes);
+ out.close();
- // first pop the start bytes
- byte[] dummy = new byte[8];
- ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- int bytesRead = in.read(dummy, 0, 8);
- assert bytesRead == 8;
- for (int i = 1; i < 9; i++) assert dummy[i - 1] == i : "Start byte stream corrupted!";
- cs2.fromStream(new UnclosableObjectInputStream(new ObjectInputStream(in)));
- bytesRead = in.read(dummy, 0, 8);
- assert bytesRead == 8;
- for (int i = 8; i > 0; i--) assert dummy[8 - i] == i : "Start byte stream corrupted!";
+ // first pop the start bytes
+ byte[] dummy = new byte[8];
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+ int bytesRead = in.read(dummy, 0, 8);
+ assert bytesRead == 8;
+ for (int i = 1; i < 9; i++) assert dummy[i - 1] == i : "Start byte stream corrupted!";
+ cs2.fromStream(new UnclosableObjectInputStream(new ObjectInputStream(in)));
+ bytesRead = in.read(dummy, 0, 8);
+ assert bytesRead == 8;
+ for (int i = 8; i > 0; i--) assert dummy[8 - i] == i : "Start byte stream corrupted!";
- Set<InternalCacheEntry> set = cs2.loadAll();
+ Set<InternalCacheEntry> set = cs2.loadAll();
- assert set.size() == 3;
- Set expected = new HashSet();
- expected.add("k1");
- expected.add("k2");
- expected.add("k3");
- for (InternalCacheEntry se : set) assert expected.remove(se.getKey());
- assert expected.isEmpty();
- }
+ assert set.size() == 3;
+ Set expected = new HashSet();
+ expected.add("k1");
+ expected.add("k2");
+ expected.add("k3");
+ for (InternalCacheEntry se : set) assert expected.remove(se.getKey());
+ assert expected.isEmpty();
+ }
}
\ No newline at end of file
More information about the infinispan-commits
mailing list