|
@@ -18,15 +18,16 @@
|
|
|
|
|
|
package org.apache.hadoop.yarn.server.sharedcachemanager;
|
|
package org.apache.hadoop.yarn.server.sharedcachemanager;
|
|
|
|
|
|
-import static org.junit.Assert.assertEquals;
|
|
|
|
-import static org.junit.Assert.assertNotNull;
|
|
|
|
-import static org.junit.Assert.assertNull;
|
|
|
|
-import static org.mockito.Mockito.spy;
|
|
|
|
-
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.InetSocketAddress;
|
|
|
|
|
|
|
|
+import org.junit.jupiter.api.AfterAll;
|
|
|
|
+import org.junit.jupiter.api.AfterEach;
|
|
|
|
+import org.junit.jupiter.api.BeforeAll;
|
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
+
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.ipc.RPC;
|
|
import org.apache.hadoop.ipc.RPC;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
@@ -42,11 +43,11 @@ import org.apache.hadoop.yarn.server.sharedcachemanager.metrics.ClientSCMMetrics
|
|
import org.apache.hadoop.yarn.server.sharedcachemanager.store.InMemorySCMStore;
|
|
import org.apache.hadoop.yarn.server.sharedcachemanager.store.InMemorySCMStore;
|
|
import org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore;
|
|
import org.apache.hadoop.yarn.server.sharedcachemanager.store.SCMStore;
|
|
import org.apache.hadoop.yarn.server.sharedcachemanager.store.SharedCacheResourceReference;
|
|
import org.apache.hadoop.yarn.server.sharedcachemanager.store.SharedCacheResourceReference;
|
|
-import org.junit.After;
|
|
|
|
-import org.junit.AfterClass;
|
|
|
|
-import org.junit.Before;
|
|
|
|
-import org.junit.BeforeClass;
|
|
|
|
-import org.junit.Test;
|
|
|
|
|
|
+
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
|
+import static org.mockito.Mockito.spy;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -55,7 +56,7 @@ import org.junit.Test;
|
|
public class TestClientSCMProtocolService {
|
|
public class TestClientSCMProtocolService {
|
|
private static File testDir = null;
|
|
private static File testDir = null;
|
|
|
|
|
|
- @BeforeClass
|
|
|
|
|
|
+ @BeforeAll
|
|
public static void setupTestDirs() throws IOException {
|
|
public static void setupTestDirs() throws IOException {
|
|
testDir = new File("target",
|
|
testDir = new File("target",
|
|
TestSharedCacheUploaderService.class.getCanonicalName());
|
|
TestSharedCacheUploaderService.class.getCanonicalName());
|
|
@@ -64,7 +65,7 @@ public class TestClientSCMProtocolService {
|
|
testDir = testDir.getAbsoluteFile();
|
|
testDir = testDir.getAbsoluteFile();
|
|
}
|
|
}
|
|
|
|
|
|
- @AfterClass
|
|
|
|
|
|
+ @AfterAll
|
|
public static void cleanupTestDirs() throws IOException {
|
|
public static void cleanupTestDirs() throws IOException {
|
|
if (testDir != null) {
|
|
if (testDir != null) {
|
|
testDir.delete();
|
|
testDir.delete();
|
|
@@ -78,7 +79,7 @@ public class TestClientSCMProtocolService {
|
|
private final RecordFactory recordFactory = RecordFactoryProvider
|
|
private final RecordFactory recordFactory = RecordFactoryProvider
|
|
.getRecordFactory(null);
|
|
.getRecordFactory(null);
|
|
|
|
|
|
- @Before
|
|
|
|
|
|
+ @BeforeEach
|
|
public void startUp() {
|
|
public void startUp() {
|
|
Configuration conf = new Configuration();
|
|
Configuration conf = new Configuration();
|
|
conf.set(YarnConfiguration.SCM_STORE_CLASS,
|
|
conf.set(YarnConfiguration.SCM_STORE_CLASS,
|
|
@@ -105,7 +106,7 @@ public class TestClientSCMProtocolService {
|
|
conf);
|
|
conf);
|
|
}
|
|
}
|
|
|
|
|
|
- @After
|
|
|
|
|
|
+ @AfterEach
|
|
public void cleanUp() {
|
|
public void cleanUp() {
|
|
if (store != null) {
|
|
if (store != null) {
|
|
store.stop();
|
|
store.stop();
|
|
@@ -124,19 +125,19 @@ public class TestClientSCMProtocolService {
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void testUse_MissingEntry() throws Exception {
|
|
|
|
|
|
+ void testUse_MissingEntry() throws Exception {
|
|
long misses = ClientSCMMetrics.getInstance().getCacheMisses();
|
|
long misses = ClientSCMMetrics.getInstance().getCacheMisses();
|
|
UseSharedCacheResourceRequest request =
|
|
UseSharedCacheResourceRequest request =
|
|
recordFactory.newRecordInstance(UseSharedCacheResourceRequest.class);
|
|
recordFactory.newRecordInstance(UseSharedCacheResourceRequest.class);
|
|
request.setResourceKey("key1");
|
|
request.setResourceKey("key1");
|
|
request.setAppId(createAppId(1, 1L));
|
|
request.setAppId(createAppId(1, 1L));
|
|
assertNull(clientSCMProxy.use(request).getPath());
|
|
assertNull(clientSCMProxy.use(request).getPath());
|
|
- assertEquals("Client SCM metrics aren't updated.", 1, ClientSCMMetrics
|
|
|
|
- .getInstance().getCacheMisses() - misses);
|
|
|
|
|
|
+ assertEquals(1, ClientSCMMetrics
|
|
|
|
+ .getInstance().getCacheMisses() - misses, "Client SCM metrics aren't updated.");
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void testUse_ExistingEntry_NoAppIds() throws Exception {
|
|
|
|
|
|
+ void testUse_ExistingEntry_NoAppIds() throws Exception {
|
|
// Pre-populate the SCM with one cache entry
|
|
// Pre-populate the SCM with one cache entry
|
|
store.addResource("key1", "foo.jar");
|
|
store.addResource("key1", "foo.jar");
|
|
|
|
|
|
@@ -150,13 +151,13 @@ public class TestClientSCMProtocolService {
|
|
String expectedPath = testDir.getAbsolutePath() + "/k/e/y/key1/foo.jar";
|
|
String expectedPath = testDir.getAbsolutePath() + "/k/e/y/key1/foo.jar";
|
|
assertEquals(expectedPath, clientSCMProxy.use(request).getPath());
|
|
assertEquals(expectedPath, clientSCMProxy.use(request).getPath());
|
|
assertEquals(1, store.getResourceReferences("key1").size());
|
|
assertEquals(1, store.getResourceReferences("key1").size());
|
|
- assertEquals("Client SCM metrics aren't updated.", 1, ClientSCMMetrics
|
|
|
|
- .getInstance().getCacheHits() - hits);
|
|
|
|
|
|
+ assertEquals(1, ClientSCMMetrics
|
|
|
|
+ .getInstance().getCacheHits() - hits, "Client SCM metrics aren't updated.");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void testUse_ExistingEntry_OneId() throws Exception {
|
|
|
|
|
|
+ void testUse_ExistingEntry_OneId() throws Exception {
|
|
// Pre-populate the SCM with one cache entry
|
|
// Pre-populate the SCM with one cache entry
|
|
store.addResource("key1", "foo.jar");
|
|
store.addResource("key1", "foo.jar");
|
|
store.addResourceReference("key1",
|
|
store.addResourceReference("key1",
|
|
@@ -174,12 +175,12 @@ public class TestClientSCMProtocolService {
|
|
String expectedPath = testDir.getAbsolutePath() + "/k/e/y/key1/foo.jar";
|
|
String expectedPath = testDir.getAbsolutePath() + "/k/e/y/key1/foo.jar";
|
|
assertEquals(expectedPath, clientSCMProxy.use(request).getPath());
|
|
assertEquals(expectedPath, clientSCMProxy.use(request).getPath());
|
|
assertEquals(2, store.getResourceReferences("key1").size());
|
|
assertEquals(2, store.getResourceReferences("key1").size());
|
|
- assertEquals("Client SCM metrics aren't updated.", 1, ClientSCMMetrics
|
|
|
|
- .getInstance().getCacheHits() - hits);
|
|
|
|
|
|
+ assertEquals(1, ClientSCMMetrics
|
|
|
|
+ .getInstance().getCacheHits() - hits, "Client SCM metrics aren't updated.");
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void testUse_ExistingEntry_DupId() throws Exception {
|
|
|
|
|
|
+ void testUse_ExistingEntry_DupId() throws Exception {
|
|
// Pre-populate the SCM with one cache entry
|
|
// Pre-populate the SCM with one cache entry
|
|
store.addResource("key1", "foo.jar");
|
|
store.addResource("key1", "foo.jar");
|
|
UserGroupInformation testUGI = UserGroupInformation.getCurrentUser();
|
|
UserGroupInformation testUGI = UserGroupInformation.getCurrentUser();
|
|
@@ -201,12 +202,12 @@ public class TestClientSCMProtocolService {
|
|
assertEquals(expectedPath, clientSCMProxy.use(request).getPath());
|
|
assertEquals(expectedPath, clientSCMProxy.use(request).getPath());
|
|
assertEquals(1, store.getResourceReferences("key1").size());
|
|
assertEquals(1, store.getResourceReferences("key1").size());
|
|
|
|
|
|
- assertEquals("Client SCM metrics aren't updated.", 1, ClientSCMMetrics
|
|
|
|
- .getInstance().getCacheHits() - hits);
|
|
|
|
|
|
+ assertEquals(1, ClientSCMMetrics
|
|
|
|
+ .getInstance().getCacheHits() - hits, "Client SCM metrics aren't updated.");
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void testRelease_ExistingEntry_NonExistantAppId() throws Exception {
|
|
|
|
|
|
+ void testRelease_ExistingEntry_NonExistantAppId() throws Exception {
|
|
// Pre-populate the SCM with one cache entry
|
|
// Pre-populate the SCM with one cache entry
|
|
store.addResource("key1", "foo.jar");
|
|
store.addResource("key1", "foo.jar");
|
|
store.addResourceReference("key1",
|
|
store.addResourceReference("key1",
|
|
@@ -224,13 +225,14 @@ public class TestClientSCMProtocolService {
|
|
assertEquals(1, store.getResourceReferences("key1").size());
|
|
assertEquals(1, store.getResourceReferences("key1").size());
|
|
|
|
|
|
assertEquals(
|
|
assertEquals(
|
|
- "Client SCM metrics were updated when a release did not happen", 0,
|
|
|
|
- ClientSCMMetrics.getInstance().getCacheReleases() - releases);
|
|
|
|
|
|
+ 0,
|
|
|
|
+ ClientSCMMetrics.getInstance().getCacheReleases() - releases,
|
|
|
|
+ "Client SCM metrics were updated when a release did not happen");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void testRelease_ExistingEntry_WithAppId() throws Exception {
|
|
|
|
|
|
+ void testRelease_ExistingEntry_WithAppId() throws Exception {
|
|
// Pre-populate the SCM with one cache entry
|
|
// Pre-populate the SCM with one cache entry
|
|
store.addResource("key1", "foo.jar");
|
|
store.addResource("key1", "foo.jar");
|
|
UserGroupInformation testUGI = UserGroupInformation.getCurrentUser();
|
|
UserGroupInformation testUGI = UserGroupInformation.getCurrentUser();
|
|
@@ -249,13 +251,13 @@ public class TestClientSCMProtocolService {
|
|
clientSCMProxy.release(request);
|
|
clientSCMProxy.release(request);
|
|
assertEquals(0, store.getResourceReferences("key1").size());
|
|
assertEquals(0, store.getResourceReferences("key1").size());
|
|
|
|
|
|
- assertEquals("Client SCM metrics aren't updated.", 1, ClientSCMMetrics
|
|
|
|
- .getInstance().getCacheReleases() - releases);
|
|
|
|
|
|
+ assertEquals(1, ClientSCMMetrics
|
|
|
|
+ .getInstance().getCacheReleases() - releases, "Client SCM metrics aren't updated.");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void testRelease_MissingEntry() throws Exception {
|
|
|
|
|
|
+ void testRelease_MissingEntry() throws Exception {
|
|
|
|
|
|
long releases = ClientSCMMetrics.getInstance().getCacheReleases();
|
|
long releases = ClientSCMMetrics.getInstance().getCacheReleases();
|
|
|
|
|
|
@@ -268,8 +270,9 @@ public class TestClientSCMProtocolService {
|
|
assertNotNull(store.getResourceReferences("key2"));
|
|
assertNotNull(store.getResourceReferences("key2"));
|
|
assertEquals(0, store.getResourceReferences("key2").size());
|
|
assertEquals(0, store.getResourceReferences("key2").size());
|
|
assertEquals(
|
|
assertEquals(
|
|
- "Client SCM metrics were updated when a release did not happen.", 0,
|
|
|
|
- ClientSCMMetrics.getInstance().getCacheReleases() - releases);
|
|
|
|
|
|
+ 0,
|
|
|
|
+ ClientSCMMetrics.getInstance().getCacheReleases() - releases,
|
|
|
|
+ "Client SCM metrics were updated when a release did not happen.");
|
|
}
|
|
}
|
|
|
|
|
|
private ApplicationId createAppId(int id, long timestamp) {
|
|
private ApplicationId createAppId(int id, long timestamp) {
|