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"));
}
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();
}
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();
}
}
Aggregations