use of org.apache.storm.daemon.supervisor.IAdvancedFSOps in project storm by apache.
the class LocalizedResourceRetentionSetTest method testCleanup.
@Test
public void testCleanup() throws Exception {
ClientBlobStore mockBlobstore = mock(ClientBlobStore.class);
when(mockBlobstore.getBlobMeta(any())).thenReturn(new ReadableBlobMeta(new SettableBlobMeta(), 1));
PortAndAssignment pna1 = new PortAndAssignmentImpl(1, new LocalAssignment("topo1", Collections.emptyList()));
String user = "user";
Map<String, Object> conf = new HashMap<>();
IAdvancedFSOps ops = mock(IAdvancedFSOps.class);
LocalizedResourceRetentionSet lrretset = spy(new LocalizedResourceRetentionSet(10));
ConcurrentMap<String, LocalizedResource> lrFiles = new ConcurrentHashMap<>();
ConcurrentMap<String, LocalizedResource> lrArchives = new ConcurrentHashMap<>();
StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
// no reference to key1
LocalizedResource localresource1 = new LocalizedResource("key1", Paths.get("./target/TESTING/testfile1"), false, ops, conf, user, metricsRegistry);
localresource1.setSize(10);
// no reference to archive1
LocalizedResource archiveresource1 = new LocalizedResource("archive1", Paths.get("./target/TESTING/testarchive1"), true, ops, conf, user, metricsRegistry);
archiveresource1.setSize(20);
// reference to key2
LocalizedResource localresource2 = new LocalizedResource("key2", Paths.get("./target/TESTING/testfile2"), false, ops, conf, user, metricsRegistry);
localresource2.addReference(pna1, null);
// check adding reference to local resource with topology of same name
localresource2.addReference(pna1, null);
localresource2.setSize(10);
lrFiles.put("key1", localresource1);
lrFiles.put("key2", localresource2);
lrArchives.put("archive1", archiveresource1);
lrretset.addResources(lrFiles);
lrretset.addResources(lrArchives);
assertEquals("number to clean is not 2", 2, lrretset.getSizeWithNoReferences());
lrretset.cleanup(mockBlobstore);
assertEquals("resource not cleaned up", 0, lrretset.getSizeWithNoReferences());
}
use of org.apache.storm.daemon.supervisor.IAdvancedFSOps in project storm by apache.
the class LocalizedResourceRetentionSetTest method testAddResources.
@Test
public void testAddResources() throws Exception {
PortAndAssignment pna1 = new PortAndAssignmentImpl(1, new LocalAssignment("topo1", Collections.emptyList()));
PortAndAssignment pna2 = new PortAndAssignmentImpl(1, new LocalAssignment("topo2", Collections.emptyList()));
String user = "user";
Map<String, Object> conf = new HashMap<>();
IAdvancedFSOps ops = mock(IAdvancedFSOps.class);
LocalizedResourceRetentionSet lrretset = new LocalizedResourceRetentionSet(10);
ConcurrentMap<String, LocalizedResource> lrset = new ConcurrentHashMap<>();
StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
LocalizedResource localresource1 = new LocalizedResource("key1", Paths.get("testfile1"), false, ops, conf, user, metricsRegistry);
localresource1.addReference(pna1, null);
LocalizedResource localresource2 = new LocalizedResource("key2", Paths.get("testfile2"), false, ops, conf, user, metricsRegistry);
localresource2.addReference(pna1, null);
// check adding reference to local resource with topology of same name
localresource2.addReference(pna2, null);
lrset.put("key1", localresource1);
lrset.put("key2", localresource2);
lrretset.addResources(lrset);
assertEquals("number to clean is not 0 " + lrretset.noReferences, 0, lrretset.getSizeWithNoReferences());
assertTrue(localresource1.removeReference(pna1));
lrretset = new LocalizedResourceRetentionSet(10);
lrretset.addResources(lrset);
assertEquals("number to clean is not 1 " + lrretset.noReferences, 1, lrretset.getSizeWithNoReferences());
assertTrue(localresource2.removeReference(pna1));
lrretset = new LocalizedResourceRetentionSet(10);
lrretset.addResources(lrset);
assertEquals("number to clean is not 1 " + lrretset.noReferences, 1, lrretset.getSizeWithNoReferences());
assertTrue(localresource2.removeReference(pna2));
lrretset = new LocalizedResourceRetentionSet(10);
lrretset.addResources(lrset);
assertEquals("number to clean is not 2 " + lrretset.noReferences, 2, lrretset.getSizeWithNoReferences());
}
Aggregations