Search in sources :

Example 1 with IAdvancedFSOps

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());
}
Also used : ClientBlobStore(org.apache.storm.blobstore.ClientBlobStore) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IAdvancedFSOps(org.apache.storm.daemon.supervisor.IAdvancedFSOps) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) ReadableBlobMeta(org.apache.storm.generated.ReadableBlobMeta) LocalAssignment(org.apache.storm.generated.LocalAssignment) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta) Test(org.junit.Test)

Example 2 with IAdvancedFSOps

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());
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IAdvancedFSOps(org.apache.storm.daemon.supervisor.IAdvancedFSOps) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) LocalAssignment(org.apache.storm.generated.LocalAssignment) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 IAdvancedFSOps (org.apache.storm.daemon.supervisor.IAdvancedFSOps)2 LocalAssignment (org.apache.storm.generated.LocalAssignment)2 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)2 Test (org.junit.Test)2 ClientBlobStore (org.apache.storm.blobstore.ClientBlobStore)1 ReadableBlobMeta (org.apache.storm.generated.ReadableBlobMeta)1 SettableBlobMeta (org.apache.storm.generated.SettableBlobMeta)1