BlobStore blobStore = context.getBlobStore(); if ( blobStore.createContainerInLocation(null, bucketName) ) { logger.info( "Created bucket {}", bucketName ); BlobStore blobStore = context.getBlobStore(); BlobBuilder blobBuilder = blobStore.blobBuilder( filename ) .payload( ephemeral ) .contentMD5(Files.hash( ephemeral, Hashing.md5() )) .contentType("application/json"); Blob blob = blobBuilder.build(); final String uploadedFile = blobStore.putBlob( bucketName, blob, PutOptions.Builder.multipart() );
@Override protected void after() { logger.debug("S3 proxy is stopping"); try { s3Proxy.stop(); BlobStore blobStore = blobStoreContext.getBlobStore(); for (StorageMetadata metadata : blobStore.list()) { blobStore.deleteContainer(metadata.getName()); } blobStoreContext.close(); } catch (Exception e) { throw new RuntimeException("Unable to stop S3 proxy", e); } FileUtils.deleteQuietly(blobStoreLocation); logger.debug("S3 proxy has stopped"); }
.prepareOutputFileName(organization.getName(), "applications"); blobStore = context.getBlobStore(); if (!blobStore.blobExists(bucketName, expectedFileName)) { blobStore.deleteContainer(bucketName); Assert.fail("Blob does not exist: " + expectedFileName); Blob bo = blobStore.getBlob(bucketName, expectedFileName); Long numOfFiles = blobStore.countBlobs(bucketName); Long numWeWant = 1L; blobStore.deleteContainer(bucketName); assertEquals(numOfFiles, numWeWant); assertNotNull(bo); blobStore.deleteContainer(bucketName);
.overrides(overrides).buildView(BlobStoreContext.class); BlobStore blobStore = context.getBlobStore(); final PageSet<? extends StorageMetadata> blobStoreList = blobStore.list(); blobStore.deleteContainer(s.getName()); } catch ( ContainerNotFoundException cnfe ) { logger.warn("Attempted to delete bucket {} but it is already deleted", cnfe );
@Test public void testSignPutBlobWithTime() throws Exception { BlobStore signPutBloblWithTime = requestsSendResponses(init()); Blob blob = signPutBloblWithTime.blobBuilder(name).payload(text).contentType("text/plain").build(); HttpRequest compare = putBlobWithTime(); compare.setPayload(blob.getPayload()); assertEquals(signPutBloblWithTime.getContext().getSigner().signPutBlob(container, blob, 3l /* seconds */), compare); }
@Test public void testSignRemoveUrl() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signRemoveBlob(container, name); assertEquals(request.getFilters().size(), 0); view.utils().http().invoke(request); assert !view.getBlobStore().blobExists(container, name); } finally { returnContainer(container); } } }
@Test(groups = { "integration", "live" }) public void testListContainer() throws InterruptedException, ExecutionException, TimeoutException { String containerName = getContainerName(); try { add15UnderRoot(containerName); Set<? extends StorageMetadata> container = view.getBlobStore().list(containerName); assertEquals(container.size(), 15); } finally { returnContainer(containerName); } }
@Test public void testSignPutBlob() throws Exception { BlobStore signPutBlob = requestsSendResponses(init()); Blob blob = signPutBlob.blobBuilder("name").forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 }) .contentType("text/plain").expires(new Date(1000)).build(); HttpRequest compare = putBlob(); compare.setPayload(blob.getPayload()); assertEquals(signPutBlob.getContext().getSigner().signPutBlob(container, blob), compare); }
@Test(groups = { "integration", "live" }) public void deleteObjectNoContainer() { try { view.getBlobStore().removeBlob("donb", "test"); } catch (HttpResponseException e) { assertEquals(e.getResponse().getStatusCode(), 404); } catch (ContainerNotFoundException e) { } }
@Test(dataProvider = "ignoreOnMacOSX") public void testGetDirectoryBlob() throws IOException { blobStore.createContainerInLocation(null, CONTAINER_NAME); String blobKey = TestUtils.createRandomBlobKey("a/b/c/directory-", "/"); blobStore.putBlob(CONTAINER_NAME, createDirBlob(blobKey)); assertTrue(blobStore.blobExists(CONTAINER_NAME, blobKey)); Blob blob = blobStore.getBlob(CONTAINER_NAME, blobKey); assertEquals(blob.getMetadata().getName(), blobKey, "Created blob name is different"); assertTrue(!blobStore.blobExists(CONTAINER_NAME, blobKey.substring(0, blobKey.length() - 1))); }
@Test(groups = "live") public void testPublicAccess() throws InterruptedException, MalformedURLException, IOException { final String containerName = getScratchContainerName(); try { view.getBlobStore().createContainerInLocation(null, containerName, publicRead()); assertConsistencyAwareContainerExists(containerName); defaultLocation = Iterables.find(view.getBlobStore().list(), new Predicate<StorageMetadata>() { @Override public boolean apply(@Nullable StorageMetadata input) { return input.getName().equals(containerName); } }).getLocation(); view.getBlobStore().putBlob(containerName, view.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build()); assertConsistencyAwareContainerSize(containerName, 1); BlobMetadata metadata = view.getBlobStore().blobMetadata(containerName, "hello"); assert metadata.getPublicUri() != null : metadata; assertEquals(Strings2.toStringAndClose(view.utils().http().get(metadata.getPublicUri())), TEST_STRING); } finally { // this container is now public, so we can't reuse it directly recycleContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testDuplicateCreateContainer() { BlobStore blobStore = view.getBlobStore(); Location location = null; String container = "container"; boolean created; created = blobStore.createContainerInLocation(location, container); assertTrue(created); created = blobStore.createContainerInLocation(location, container); assertFalse(created); } }
@Test(groups = { "integration", "live" }) public void testPutTwiceIsOkAndDoesntOverwrite() throws InterruptedException { String containerName = getContainerName(); try { view.getBlobStore().createContainerInLocation(null, containerName); Blob blob = view.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build(); view.getBlobStore().putBlob(containerName, blob); view.getBlobStore().createContainerInLocation(null, containerName); assertEquals(view.getBlobStore().countBlobs(containerName), 1); } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void deleteObjectNotFound() throws InterruptedException { String container = getContainerName(); String name = "test"; try { view.getBlobStore().removeBlob(container, name); } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testGetTwoRanges() throws InterruptedException, IOException { String container = getContainerName(); try { String name = "apples"; addObjectAndValidateContent(container, name); Blob blob = view.getBlobStore().getBlob(container, name, range(0, 5).range(6, TEST_STRING.length())); validateMetadata(blob.getMetadata(), container, name); assertEquals(getContentAsStringOrNullAndClose(blob), TEST_STRING); } finally { returnContainer(container); } }
@Test public void testListAllWhenOnePage() throws Exception { BlobStore blobStore = createMock(BlobStore.class); ListContainerOptions options = ListContainerOptions.NONE; StorageMetadata v1 = createMock(StorageMetadata.class); PageSet<StorageMetadata> pageSet = new PageSetImpl<StorageMetadata>(ImmutableList.of(v1), null); EasyMock.<PageSet<? extends StorageMetadata>> expect(blobStore.list(containerName, options)).andReturn(pageSet) .once(); EasyMock.replay(blobStore); Iterable<StorageMetadata> iterable = BlobStores.listAll(blobStore, containerName, options); assertEquals(ImmutableList.copyOf(iterable), ImmutableList.of(v1)); }
@Test(dataProvider = "ignoreOnMacOSX") public void testListDirectoryBlobs() { blobStore.createContainerInLocation(null, CONTAINER_NAME); checkForContainerContent(CONTAINER_NAME, null); Set<String> dirs = ImmutableSet.of(TestUtils.createRandomBlobKey("directory-", File.separator)); for (String d : dirs) { blobStore.putBlob(CONTAINER_NAME, createDirBlob(d)); assertTrue(blobStore.blobExists(CONTAINER_NAME, d)); } checkForContainerContent(CONTAINER_NAME, dirs); }
public void testCreateListDestroyContainer() throws IOException { context.getBlobStore().createContainerInLocation(null, testContainerName); context.getBlobStore().list(testContainerName); PageSet<? extends StorageMetadata> ps = context.getBlobStore().list(); assertHasItemNamed(ps, testContainerName); Blob b = context.getBlobStore().blobBuilder("my-blob-1").payload(Streams.newInputStreamWithContents("hello world")).build(); context.getBlobStore().putBlob(testContainerName, b); Blob b2 = context.getBlobStore().getBlob(testContainerName, "my-blob-1"); Assert.assertEquals(Streams.readFullyStringAndClose(b2.getPayload().openStream()), "hello world"); context.getBlobStore().deleteContainer(testContainerName); }
@Test(groups = { "integration", "live" }) public void containerDoesntExist() { assert !view.getBlobStore().containerExists("forgetaboutit"); assert !view.getBlobStore().containerExists("cloudcachestorefunctionalintegrationtest-first"); }