Index: TestS3Ds.java =================================================================== --- TestS3Ds.java (revision 1672003) +++ TestS3Ds.java (working copy) @@ -50,40 +50,45 @@ protected Properties props; + protected String config; + public TestS3Ds() throws IOException { - config = System.getProperty(CONFIG); - memoryBackend = false; - noCache = false; - props = Utils.readConfig(config); - } + System.setProperty( + TestCaseBase.CONFIG, + "C:/src/apache/jackrabbit-encryp-changes/jackrabbit/jackrabbit-aws-ext/src/test/resources/aws.properties"); + config = System.getProperty(CONFIG); + props = Utils.readConfig(System.getProperty(CONFIG)); + } + @Override protected void setUp() throws Exception { startTime = new Date(); super.setUp(); String bucket = String.valueOf(randomGen.nextInt(9999)) + "-" - + String.valueOf(randomGen.nextInt(9999)) + "-test"; - props.setProperty(S3Constants.S3_BUCKET, bucket ); + + String.valueOf(randomGen.nextInt(9999)) + "-test"; + props.setProperty(S3Constants.S3_BUCKET, bucket); // delete bucket if exists deleteBucket(bucket); } - protected void tearDown() { + + @Override + protected void tearDown() { try { deleteBucket(); super.tearDown(); - } catch ( Exception ignore ) { + } catch (Exception ignore) { } } + @Override protected CachingDataStore createDataStore() throws RepositoryException { - ds = new S3TestDataStore(props); - ds.setConfig(config); - if (noCache) { - ds.setCacheSize(0); - } - ds.init(dataStoreDir); + S3DataStore s3ds = new S3DataStore(); + s3ds.setProperties(props); + s3ds.setSecret("123456"); + s3ds.init(dataStoreDir); sleep(1000); - return ds; + return s3ds; } /** @@ -93,20 +98,22 @@ * Cleaning of bucket after test run. */ public void deleteBucket() throws Exception { - Backend backend = ds.getBackend(); - String bucket = ((S3Backend)backend).getBucket(); + Backend backend = ((S3DataStore) ds).getBackend(); + String bucket = ((S3Backend) backend).getBucket(); deleteBucket(bucket); } + public void deleteBucket(String bucket) throws Exception { LOG.info("deleting bucket [" + bucket + "]"); Properties props = Utils.readConfig(config); AmazonS3Client s3service = Utils.openService(props); TransferManager tmx = new TransferManager(s3service); + if (s3service.doesBucketExist(bucket)) { for (int i = 0; i < 4; i++) { tmx.abortMultipartUploads(bucket, startTime); ObjectListing prevObjectListing = s3service.listObjects(bucket); - while (prevObjectListing != null ) { + while (prevObjectListing != null) { List deleteList = new ArrayList(); for (S3ObjectSummary s3ObjSumm : prevObjectListing.getObjectSummaries()) { deleteList.add(new DeleteObjectsRequest.KeyVersion( @@ -124,11 +131,11 @@ } s3service.deleteBucket(bucket); LOG.info("bucket [ " + bucket + "] deleted"); + } else { LOG.info("bucket [" + bucket + "] doesn't exists"); } - tmx.shutdownNow(); - s3service.shutdown(); + tmx.shutdownNow(); + s3service.shutdown(); } - -} +} \ No newline at end of file Index: TestS3DSAsyncTouch.java =================================================================== --- TestS3DSAsyncTouch.java (revision 1672003) +++ TestS3DSAsyncTouch.java (working copy) @@ -33,19 +33,22 @@ public class TestS3DSAsyncTouch extends TestS3Ds { protected static final Logger LOG = LoggerFactory.getLogger(TestS3DSAsyncTouch.class); + public TestS3DSAsyncTouch() throws IOException { - config = System.getProperty(CONFIG); - memoryBackend = false; - noCache = false; + } + @Override protected CachingDataStore createDataStore() throws RepositoryException { - ds = new S3TestDataStore(props); - ds.setConfig(config); - ds.init(dataStoreDir); - ds.setTouchAsync(true); - ds.updateModifiedDateOnAccess(System.currentTimeMillis()+ 50* 1000); + S3DataStore s3ds = new S3DataStore(); + s3ds.setProperties(props); + s3ds.setTouchAsync(true); + s3ds.setSecret("123456"); + s3ds.init(dataStoreDir); + s3ds.updateModifiedDateOnAccess(System.currentTimeMillis() + 50 * 1000); sleep(1000); - return ds; + return s3ds; } } + + Index: TestS3DsCacheOff.java =================================================================== --- TestS3DsCacheOff.java (revision 1672003) +++ TestS3DsCacheOff.java (working copy) @@ -18,13 +18,16 @@ import java.io.IOException; +import javax.jcr.RepositoryException; + +import org.apache.jackrabbit.core.data.CachingDataStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Test {@link org.apache.jackrabbit.core.data.CachingDataStore} with S3Backend and local cache Off. It requires - * to pass aws config file via system property. For e.g. - * -Dconfig=/opt/cq/aws.properties. Sample aws properties located at + * Test {@link org.apache.jackrabbit.core.data.CachingDataStore} with S3Backend + * and local cache Off. It requires to pass aws config file via system property. + * For e.g. -Dconfig=/opt/cq/aws.properties. Sample aws properties located at * src/test/resources/aws.properties */ public class TestS3DsCacheOff extends TestS3Ds { @@ -32,8 +35,16 @@ protected static final Logger LOG = LoggerFactory.getLogger(TestS3DsCacheOff.class); public TestS3DsCacheOff() throws IOException { - config = System.getProperty(CONFIG); - memoryBackend = false; - noCache = true; } -} + + @Override + protected CachingDataStore createDataStore() throws RepositoryException { + S3DataStore s3ds = new S3DataStore(); + s3ds.setProperties(props); + s3ds.setCacheSize(0); + s3ds.setSecret("123456"); + s3ds.init(dataStoreDir); + sleep(1000); + return s3ds; + } +} \ No newline at end of file Index: TestS3DSWithSmallCache.java =================================================================== --- TestS3DSWithSmallCache.java (revision 1672003) +++ TestS3DSWithSmallCache.java (working copy) @@ -21,11 +21,13 @@ import javax.jcr.RepositoryException; import org.apache.jackrabbit.core.data.CachingDataStore; +import org.apache.jackrabbit.core.data.LocalCache; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + /** - * Test {@link org.apache.jackrabbit.core.data.CachingDataStore} with S3Backend and with very small size (@link - * {@link org.apache.jackrabbit.core.data.LocalCache}. It requires to pass aws config file via system property. + * Test {@link CachingDataStore} with S3Backend and with very small size (@link + * {@link LocalCache}. It requires to pass aws config file via system property. * For e.g. -Dconfig=/opt/cq/aws.properties. Sample aws properties located at * src/test/resources/aws.properties */ @@ -32,20 +34,20 @@ public class TestS3DSWithSmallCache extends TestS3Ds { protected static final Logger LOG = LoggerFactory.getLogger(TestS3DSWithSmallCache.class); + public TestS3DSWithSmallCache() throws IOException { - config = System.getProperty(CONFIG); - memoryBackend = false; - noCache = false; } + @Override protected CachingDataStore createDataStore() throws RepositoryException { - ds = new S3TestDataStore(props); - ds.setConfig(config); - ds.setCacheSize(dataLength * 10); - ds.setCachePurgeTrigFactor(0.5d); - ds.setCachePurgeResizeFactor(0.4d); - ds.init(dataStoreDir); + S3DataStore s3ds = new S3DataStore(); + s3ds.setProperties(props); + s3ds.setCacheSize(dataLength * 10); + s3ds.setCachePurgeTrigFactor(0.5d); + s3ds.setCachePurgeResizeFactor(0.4d); + s3ds.setSecret("123456"); + s3ds.init(dataStoreDir); sleep(1000); - return ds; + return s3ds; } } Index: TestS3DSWithSSES3.java =================================================================== --- TestS3DSWithSSES3.java (revision 1672003) +++ TestS3DSWithSSES3.java (working copy) @@ -35,19 +35,18 @@ protected static final Logger LOG = LoggerFactory.getLogger(TestS3DSWithSSES3.class); public TestS3DSWithSSES3() throws IOException { - config = System.getProperty(CONFIG); - memoryBackend = false; - noCache = true; } + @Override protected CachingDataStore createDataStore() throws RepositoryException { props.setProperty(S3Constants.S3_ENCRYPTION, S3Constants.S3_ENCRYPTION_SSE_S3); - ds = new S3TestDataStore(props); - ds.setConfig(config); - ds.init(dataStoreDir); + S3DataStore s3ds = new S3DataStore(); + s3ds.setProperties(props); + s3ds.setSecret("123456"); + s3ds.init(dataStoreDir); sleep(1000); - return ds; + return s3ds; } /** @@ -56,16 +55,16 @@ public void testDataMigration() { try { String bucket = props.getProperty(S3Constants.S3_BUCKET); - ds = new S3TestDataStore(props); - ds.setConfig(config); - ds.setCacheSize(0); - ds.init(dataStoreDir); + S3DataStore s3ds = new S3DataStore(); + s3ds.setProperties(props); + s3ds.setCacheSize(0); + s3ds.init(dataStoreDir); byte[] data = new byte[dataLength]; randomGen.nextBytes(data); - DataRecord rec = ds.addRecord(new ByteArrayInputStream(data)); + DataRecord rec = s3ds.addRecord(new ByteArrayInputStream(data)); assertEquals(data.length, rec.getLength()); assertRecord(data, rec); - ds.close(); + s3ds.close(); // turn encryption now. props.setProperty(S3Constants.S3_BUCKET, bucket); @@ -72,18 +71,18 @@ props.setProperty(S3Constants.S3_ENCRYPTION, S3Constants.S3_ENCRYPTION_SSE_S3); props.setProperty(S3Constants.S3_RENAME_KEYS, "true"); - ds = new S3TestDataStore(props); - ds.setConfig(config); - ds.setCacheSize(0); - ds.init(dataStoreDir); + s3ds = new S3DataStore(); + s3ds.setProperties(props); + s3ds.setCacheSize(0); + s3ds.init(dataStoreDir); - rec = ds.getRecord(rec.getIdentifier()); + rec = s3ds.getRecord(rec.getIdentifier()); assertEquals(data.length, rec.getLength()); assertRecord(data, rec); randomGen.nextBytes(data); - rec = ds.addRecord(new ByteArrayInputStream(data)); - ds.close(); + rec = s3ds.addRecord(new ByteArrayInputStream(data)); + s3ds.close(); } catch (Exception e) { LOG.error("error:", e);