Search in sources :

Example 1 with PropertyBasedS3ClientConfig

use of com.netflix.exhibitor.core.s3.PropertyBasedS3ClientConfig in project exhibitor by soabase.

the class TestS3BackupProviderBase method testGetAvailableBackupKeys.

@Test
public void testGetAvailableBackupKeys() throws Exception {
    ObjectListing listing = new ObjectListing() {

        @Override
        public List<S3ObjectSummary> getObjectSummaries() {
            List<S3ObjectSummary> list = Lists.newArrayList();
            S3ObjectSummary summary = new S3ObjectSummary();
            summary.setKey("exhibitor-backup" + S3BackupProvider.SEPARATOR + "one" + S3BackupProvider.SEPARATOR + "1234");
            list.add(summary);
            summary = new S3ObjectSummary();
            summary.setKey("exhibitor-backup" + S3BackupProvider.SEPARATOR + "two" + S3BackupProvider.SEPARATOR + "1234");
            list.add(summary);
            summary = new S3ObjectSummary();
            summary.setKey("exhibitor-backup" + S3BackupProvider.SEPARATOR + "three" + S3BackupProvider.SEPARATOR + "1234");
            list.add(summary);
            return list;
        }
    };
    MockS3Client s3Client = new MockS3Client(null, listing);
    S3BackupProvider provider = new S3BackupProvider(new MockS3ClientFactory(s3Client), new PropertyBasedS3Credential(new Properties()), new PropertyBasedS3ClientConfig(new Properties()), null);
    List<BackupMetaData> backups = provider.getAvailableBackups(null, Maps.<String, String>newHashMap());
    List<String> backupNames = Lists.transform(backups, new Function<BackupMetaData, String>() {

        @Override
        public String apply(BackupMetaData metaData) {
            return metaData.getName();
        }
    });
    Assert.assertEquals(backupNames, Arrays.asList("one", "two", "three"));
}
Also used : BackupMetaData(com.netflix.exhibitor.core.backup.BackupMetaData) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) PropertyBasedS3ClientConfig(com.netflix.exhibitor.core.s3.PropertyBasedS3ClientConfig) Properties(java.util.Properties) PropertyBasedS3Credential(com.netflix.exhibitor.core.s3.PropertyBasedS3Credential) Test(org.testng.annotations.Test)

Example 2 with PropertyBasedS3ClientConfig

use of com.netflix.exhibitor.core.s3.PropertyBasedS3ClientConfig in project exhibitor by soabase.

the class TestS3BackupProviderBase method getUploadedBytes.

private byte[] getUploadedBytes(File sourceFile) throws Exception {
    MockS3Client s3Client = new MockS3Client();
    S3BackupProvider provider = new S3BackupProvider(new MockS3ClientFactory(s3Client), new PropertyBasedS3Credential(new Properties()), new PropertyBasedS3ClientConfig(new Properties()), null);
    provider.uploadBackup(null, new BackupMetaData("test", 10), sourceFile, Maps.<String, String>newHashMap());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    for (byte[] bytes : s3Client.getUploadedBytes()) {
        out.write(bytes);
    }
    return out.toByteArray();
}
Also used : BackupMetaData(com.netflix.exhibitor.core.backup.BackupMetaData) PropertyBasedS3Credential(com.netflix.exhibitor.core.s3.PropertyBasedS3Credential) PropertyBasedS3ClientConfig(com.netflix.exhibitor.core.s3.PropertyBasedS3ClientConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties)

Example 3 with PropertyBasedS3ClientConfig

use of com.netflix.exhibitor.core.s3.PropertyBasedS3ClientConfig in project exhibitor by soabase.

the class TestS3BackupProviderBase method testDownload.

@Test
public void testDownload() throws Exception {
    InputStream in = null;
    OutputStream out = null;
    File tempFile = File.createTempFile("test", ".test");
    try {
        in = new FileInputStream(sourceFile);
        PutObjectRequest dummyRequest = new PutObjectRequest("bucket", "exhibitor-backup" + S3BackupProvider.SEPARATOR + "test" + S3BackupProvider.SEPARATOR + 1, in, null);
        MockS3Client s3Client = new MockS3Client(null, null);
        s3Client.putObject(dummyRequest);
        S3BackupProvider provider = new S3BackupProvider(new MockS3ClientFactory(s3Client), new PropertyBasedS3Credential(new Properties()), new PropertyBasedS3ClientConfig(new Properties()), null);
        out = new FileOutputStream(tempFile);
        provider.downloadBackup(null, new BackupMetaData("test", 1), out, Maps.<String, String>newHashMap());
        Assert.assertEquals(Files.toByteArray(sourceFile), Files.toByteArray(tempFile));
    } finally {
        CloseableUtils.closeQuietly(in);
        CloseableUtils.closeQuietly(out);
        //noinspection ResultOfMethodCallIgnored
        tempFile.delete();
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BackupMetaData(com.netflix.exhibitor.core.backup.BackupMetaData) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) PropertyBasedS3ClientConfig(com.netflix.exhibitor.core.s3.PropertyBasedS3ClientConfig) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) PropertyBasedS3Credential(com.netflix.exhibitor.core.s3.PropertyBasedS3Credential) File(java.io.File) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.testng.annotations.Test)

Aggregations

BackupMetaData (com.netflix.exhibitor.core.backup.BackupMetaData)3 PropertyBasedS3ClientConfig (com.netflix.exhibitor.core.s3.PropertyBasedS3ClientConfig)3 PropertyBasedS3Credential (com.netflix.exhibitor.core.s3.PropertyBasedS3Credential)3 Properties (java.util.Properties)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Test (org.testng.annotations.Test)2 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)1 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)1 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1