use of org.apache.storm.blobstore.AtomicOutputStream in project storm by apache.
the class Nimbus method cancelBlobUpload.
@SuppressWarnings("deprecation")
@Override
public void cancelBlobUpload(String session) throws AuthorizationException, TException {
try {
AtomicOutputStream os = (AtomicOutputStream) blobUploaders.get(session);
if (os == null) {
throw new RuntimeException("Blob for session " + session + " does not exist (or timed out)");
}
os.cancel();
LOG.info("Canceled uploading blob for session {}. Closing session.", session);
blobUploaders.remove(session);
} catch (Exception e) {
LOG.warn("finish blob upload exception.", e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
use of org.apache.storm.blobstore.AtomicOutputStream in project storm by apache.
the class DependencyUploaderTest method uploadFiles.
@Test
public void uploadFiles() throws Exception {
AtomicOutputStream mockOutputStream = mock(AtomicOutputStream.class);
doNothing().when(mockOutputStream).cancel();
final AtomicInteger counter = new AtomicInteger();
final Answer incrementCounter = new Answer() {
public Object answer(InvocationOnMock invocation) throws Throwable {
counter.addAndGet(1);
return null;
}
};
doAnswer(incrementCounter).when(mockOutputStream).write(anyInt());
doAnswer(incrementCounter).when(mockOutputStream).write(any(byte[].class));
doAnswer(incrementCounter).when(mockOutputStream).write(any(byte[].class), anyInt(), anyInt());
doNothing().when(mockOutputStream).close();
when(mockBlobStore.getBlobMeta(anyString())).thenThrow(new KeyNotFoundException());
when(mockBlobStore.createBlob(anyString(), any(SettableBlobMeta.class))).thenReturn(mockOutputStream);
File mockFile = createTemporaryDummyFile();
String mockFileFileNameWithoutExtension = Files.getNameWithoutExtension(mockFile.getName());
List<String> keys = sut.uploadFiles(Lists.newArrayList(mockFile), false);
assertEquals(1, keys.size());
assertTrue(keys.get(0).contains(mockFileFileNameWithoutExtension));
assertTrue(counter.get() > 0);
verify(mockOutputStream).close();
}
use of org.apache.storm.blobstore.AtomicOutputStream in project storm by apache.
the class DependencyUploaderTest method uploadArtifacts.
@Test
public void uploadArtifacts() throws Exception {
AtomicOutputStream mockOutputStream = mock(AtomicOutputStream.class);
doNothing().when(mockOutputStream).cancel();
final AtomicInteger counter = new AtomicInteger();
final Answer incrementCounter = new Answer() {
public Object answer(InvocationOnMock invocation) throws Throwable {
counter.addAndGet(1);
return null;
}
};
doAnswer(incrementCounter).when(mockOutputStream).write(anyInt());
doAnswer(incrementCounter).when(mockOutputStream).write(any(byte[].class));
doAnswer(incrementCounter).when(mockOutputStream).write(any(byte[].class), anyInt(), anyInt());
doNothing().when(mockOutputStream).close();
when(mockBlobStore.getBlobMeta(anyString())).thenThrow(new KeyNotFoundException());
when(mockBlobStore.createBlob(anyString(), any(SettableBlobMeta.class))).thenReturn(mockOutputStream);
String artifact = "group:artifact:1.0.0";
String expectedBlobKeyForArtifact = "group-artifact-1.0.0.jar";
File mockFile = createTemporaryDummyFile();
Map<String, File> artifacts = new LinkedHashMap<>();
artifacts.put(artifact, mockFile);
List<String> keys = sut.uploadArtifacts(artifacts);
assertEquals(1, keys.size());
assertTrue(keys.get(0).contains(expectedBlobKeyForArtifact));
assertTrue(counter.get() > 0);
verify(mockOutputStream).close();
}
use of org.apache.storm.blobstore.AtomicOutputStream in project storm by apache.
the class BlobStoreTest method testBasic.
public void testBasic(BlobStore store) throws Exception {
assertStoreHasExactly(store);
LOG.info("Creating test");
// Tests for case when subject == null (security turned off) and
// acls for the blob are set to WORLD_EVERYTHING
SettableBlobMeta metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING);
AtomicOutputStream out = store.createBlob("test", metadata, null);
out.write(1);
out.close();
assertStoreHasExactly(store, "test");
// Testing whether acls are set to WORLD_EVERYTHING
assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
readAssertEquals(store, "test", 1);
LOG.info("Deleting test");
store.deleteBlob("test", null);
assertStoreHasExactly(store);
// The following tests are run for both hdfs and local store to test the
// update blob interface
metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING);
LOG.info("Creating test again");
out = store.createBlob("test", metadata, null);
out.write(2);
out.close();
assertStoreHasExactly(store, "test");
readAssertEquals(store, "test", 2);
LOG.info("Updating test");
out = store.updateBlob("test", null);
out.write(3);
out.close();
assertStoreHasExactly(store, "test");
readAssertEquals(store, "test", 3);
LOG.info("Updating test again");
out = store.updateBlob("test", null);
out.write(4);
out.flush();
LOG.info("SLEEPING");
Thread.sleep(2);
if (store instanceof HdfsBlobStore) {
((HdfsBlobStore) store).fullCleanup(1);
} else {
fail("Error the blobstore is of unknowntype");
}
try {
out.close();
} catch (IOException e) {
//This is likely to happen when we try to commit something that
// was cleaned up. This is expected and acceptable.
}
}
Aggregations