|
@@ -827,10 +827,16 @@ public class TestResourceLocalizationService {
|
|
do {
|
|
do {
|
|
resource2 = getPrivateMockedResource(r);
|
|
resource2 = getPrivateMockedResource(r);
|
|
} while (resource2 == null || resource2.equals(resource1));
|
|
} while (resource2 == null || resource2.equals(resource1));
|
|
|
|
+ LocalResource resource3 = null;
|
|
|
|
+ do {
|
|
|
|
+ resource3 = getPrivateMockedResource(r);
|
|
|
|
+ } while (resource3 == null || resource3.equals(resource1)
|
|
|
|
+ || resource3.equals(resource2));
|
|
// above call to make sure we don't get identical resources.
|
|
// above call to make sure we don't get identical resources.
|
|
|
|
|
|
final LocalResourceRequest req1 = new LocalResourceRequest(resource1);
|
|
final LocalResourceRequest req1 = new LocalResourceRequest(resource1);
|
|
final LocalResourceRequest req2 = new LocalResourceRequest(resource2);
|
|
final LocalResourceRequest req2 = new LocalResourceRequest(resource2);
|
|
|
|
+ final LocalResourceRequest req3 = new LocalResourceRequest(resource3);
|
|
Map<LocalResourceVisibility, Collection<LocalResourceRequest>> rsrcs =
|
|
Map<LocalResourceVisibility, Collection<LocalResourceRequest>> rsrcs =
|
|
new HashMap<LocalResourceVisibility,
|
|
new HashMap<LocalResourceVisibility,
|
|
Collection<LocalResourceRequest>>();
|
|
Collection<LocalResourceRequest>>();
|
|
@@ -838,6 +844,7 @@ public class TestResourceLocalizationService {
|
|
new ArrayList<LocalResourceRequest>();
|
|
new ArrayList<LocalResourceRequest>();
|
|
privateResourceList.add(req1);
|
|
privateResourceList.add(req1);
|
|
privateResourceList.add(req2);
|
|
privateResourceList.add(req2);
|
|
|
|
+ privateResourceList.add(req3);
|
|
rsrcs.put(LocalResourceVisibility.PRIVATE, privateResourceList);
|
|
rsrcs.put(LocalResourceVisibility.PRIVATE, privateResourceList);
|
|
spyService.handle(new ContainerLocalizationRequestEvent(c, rsrcs));
|
|
spyService.handle(new ContainerLocalizationRequestEvent(c, rsrcs));
|
|
// Sigh. Thread init of private localizer not accessible
|
|
// Sigh. Thread init of private localizer not accessible
|
|
@@ -852,30 +859,47 @@ public class TestResourceLocalizationService {
|
|
Path localizationTokenPath = tokenPathCaptor.getValue();
|
|
Path localizationTokenPath = tokenPathCaptor.getValue();
|
|
|
|
|
|
// heartbeat from localizer
|
|
// heartbeat from localizer
|
|
- LocalResourceStatus rsrcStat1 = mock(LocalResourceStatus.class);
|
|
|
|
- LocalResourceStatus rsrcStat2 = mock(LocalResourceStatus.class);
|
|
|
|
|
|
+ LocalResourceStatus rsrc1success = mock(LocalResourceStatus.class);
|
|
|
|
+ LocalResourceStatus rsrc2pending = mock(LocalResourceStatus.class);
|
|
|
|
+ LocalResourceStatus rsrc2success = mock(LocalResourceStatus.class);
|
|
|
|
+ LocalResourceStatus rsrc3success = mock(LocalResourceStatus.class);
|
|
LocalizerStatus stat = mock(LocalizerStatus.class);
|
|
LocalizerStatus stat = mock(LocalizerStatus.class);
|
|
when(stat.getLocalizerId()).thenReturn(ctnrStr);
|
|
when(stat.getLocalizerId()).thenReturn(ctnrStr);
|
|
- when(rsrcStat1.getResource()).thenReturn(resource1);
|
|
|
|
- when(rsrcStat2.getResource()).thenReturn(resource2);
|
|
|
|
- when(rsrcStat1.getLocalSize()).thenReturn(4344L);
|
|
|
|
- when(rsrcStat2.getLocalSize()).thenReturn(2342L);
|
|
|
|
|
|
+ when(rsrc1success.getResource()).thenReturn(resource1);
|
|
|
|
+ when(rsrc2pending.getResource()).thenReturn(resource2);
|
|
|
|
+ when(rsrc2success.getResource()).thenReturn(resource2);
|
|
|
|
+ when(rsrc3success.getResource()).thenReturn(resource3);
|
|
|
|
+ when(rsrc1success.getLocalSize()).thenReturn(4344L);
|
|
|
|
+ when(rsrc2success.getLocalSize()).thenReturn(2342L);
|
|
|
|
+ when(rsrc3success.getLocalSize()).thenReturn(5345L);
|
|
URL locPath = getPath("/cache/private/blah");
|
|
URL locPath = getPath("/cache/private/blah");
|
|
- when(rsrcStat1.getLocalPath()).thenReturn(locPath);
|
|
|
|
- when(rsrcStat2.getLocalPath()).thenReturn(locPath);
|
|
|
|
- when(rsrcStat1.getStatus()).thenReturn(ResourceStatusType.FETCH_SUCCESS);
|
|
|
|
- when(rsrcStat2.getStatus()).thenReturn(ResourceStatusType.FETCH_SUCCESS);
|
|
|
|
|
|
+ when(rsrc1success.getLocalPath()).thenReturn(locPath);
|
|
|
|
+ when(rsrc2success.getLocalPath()).thenReturn(locPath);
|
|
|
|
+ when(rsrc3success.getLocalPath()).thenReturn(locPath);
|
|
|
|
+ when(rsrc1success.getStatus()).thenReturn(ResourceStatusType.FETCH_SUCCESS);
|
|
|
|
+ when(rsrc2pending.getStatus()).thenReturn(ResourceStatusType.FETCH_PENDING);
|
|
|
|
+ when(rsrc2success.getStatus()).thenReturn(ResourceStatusType.FETCH_SUCCESS);
|
|
|
|
+ when(rsrc3success.getStatus()).thenReturn(ResourceStatusType.FETCH_SUCCESS);
|
|
|
|
+
|
|
|
|
+ // Four heartbeats with sending:
|
|
|
|
+ // 1 - empty
|
|
|
|
+ // 2 - resource1 FETCH_SUCCESS
|
|
|
|
+ // 3 - resource2 FETCH_PENDING
|
|
|
|
+ // 4 - resource2 FETCH_SUCCESS, resource3 FETCH_SUCCESS
|
|
|
|
+ List<LocalResourceStatus> rsrcs4 = new ArrayList<LocalResourceStatus>();
|
|
|
|
+ rsrcs4.add(rsrc2success);
|
|
|
|
+ rsrcs4.add(rsrc3success);
|
|
when(stat.getResources())
|
|
when(stat.getResources())
|
|
.thenReturn(Collections.<LocalResourceStatus>emptyList())
|
|
.thenReturn(Collections.<LocalResourceStatus>emptyList())
|
|
- .thenReturn(Collections.singletonList(rsrcStat1))
|
|
|
|
- .thenReturn(Collections.singletonList(rsrcStat2))
|
|
|
|
- .thenReturn(Collections.<LocalResourceStatus>emptyList());
|
|
|
|
|
|
+ .thenReturn(Collections.singletonList(rsrc1success))
|
|
|
|
+ .thenReturn(Collections.singletonList(rsrc2pending))
|
|
|
|
+ .thenReturn(rsrcs4);
|
|
|
|
|
|
String localPath = Path.SEPARATOR + ContainerLocalizer.USERCACHE +
|
|
String localPath = Path.SEPARATOR + ContainerLocalizer.USERCACHE +
|
|
Path.SEPARATOR + "user0" + Path.SEPARATOR +
|
|
Path.SEPARATOR + "user0" + Path.SEPARATOR +
|
|
ContainerLocalizer.FILECACHE;
|
|
ContainerLocalizer.FILECACHE;
|
|
-
|
|
|
|
- // get first resource
|
|
|
|
|
|
+
|
|
|
|
+ // First heartbeat
|
|
LocalizerHeartbeatResponse response = spyService.heartbeat(stat);
|
|
LocalizerHeartbeatResponse response = spyService.heartbeat(stat);
|
|
assertEquals(LocalizerAction.LIVE, response.getLocalizerAction());
|
|
assertEquals(LocalizerAction.LIVE, response.getLocalizerAction());
|
|
assertEquals(1, response.getResourceSpecs().size());
|
|
assertEquals(1, response.getResourceSpecs().size());
|
|
@@ -888,7 +912,7 @@ public class TestResourceLocalizationService {
|
|
assertTrue(localizedPath.getFile().endsWith(
|
|
assertTrue(localizedPath.getFile().endsWith(
|
|
localPath + Path.SEPARATOR + "10"));
|
|
localPath + Path.SEPARATOR + "10"));
|
|
|
|
|
|
- // get second resource
|
|
|
|
|
|
+ // Second heartbeat
|
|
response = spyService.heartbeat(stat);
|
|
response = spyService.heartbeat(stat);
|
|
assertEquals(LocalizerAction.LIVE, response.getLocalizerAction());
|
|
assertEquals(LocalizerAction.LIVE, response.getLocalizerAction());
|
|
assertEquals(1, response.getResourceSpecs().size());
|
|
assertEquals(1, response.getResourceSpecs().size());
|
|
@@ -902,16 +926,21 @@ public class TestResourceLocalizationService {
|
|
assertTrue(localizedPath.getFile().endsWith(
|
|
assertTrue(localizedPath.getFile().endsWith(
|
|
localPath + Path.SEPARATOR + "0" + Path.SEPARATOR + "11"));
|
|
localPath + Path.SEPARATOR + "0" + Path.SEPARATOR + "11"));
|
|
|
|
|
|
- // empty rsrc
|
|
|
|
|
|
+ // Third heartbeat
|
|
response = spyService.heartbeat(stat);
|
|
response = spyService.heartbeat(stat);
|
|
assertEquals(LocalizerAction.LIVE, response.getLocalizerAction());
|
|
assertEquals(LocalizerAction.LIVE, response.getLocalizerAction());
|
|
- assertEquals(0, response.getResourceSpecs().size());
|
|
|
|
|
|
+ assertEquals(1, response.getResourceSpecs().size());
|
|
|
|
+ assertEquals(req3, new LocalResourceRequest(response.getResourceSpecs()
|
|
|
|
+ .get(0).getResource()));
|
|
|
|
+ localizedPath =
|
|
|
|
+ response.getResourceSpecs().get(0).getDestinationDirectory();
|
|
|
|
+ assertTrue(localizedPath.getFile().endsWith(
|
|
|
|
+ localPath + Path.SEPARATOR + "1" + Path.SEPARATOR + "12"));
|
|
|
|
|
|
// get shutdown
|
|
// get shutdown
|
|
response = spyService.heartbeat(stat);
|
|
response = spyService.heartbeat(stat);
|
|
assertEquals(LocalizerAction.DIE, response.getLocalizerAction());
|
|
assertEquals(LocalizerAction.DIE, response.getLocalizerAction());
|
|
|
|
|
|
-
|
|
|
|
dispatcher.await();
|
|
dispatcher.await();
|
|
// verify container notification
|
|
// verify container notification
|
|
ArgumentMatcher<ContainerEvent> matchesContainerLoc =
|
|
ArgumentMatcher<ContainerEvent> matchesContainerLoc =
|
|
@@ -923,8 +952,8 @@ public class TestResourceLocalizationService {
|
|
&& c.getContainerId() == evt.getContainerID();
|
|
&& c.getContainerId() == evt.getContainerID();
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- // total 2 resource localzation calls. one for each resource.
|
|
|
|
- verify(containerBus, times(2)).handle(argThat(matchesContainerLoc));
|
|
|
|
|
|
+ // total 3 resource localzation calls. one for each resource.
|
|
|
|
+ verify(containerBus, times(3)).handle(argThat(matchesContainerLoc));
|
|
|
|
|
|
// Verify deletion of localization token.
|
|
// Verify deletion of localization token.
|
|
verify(delService).delete((String)isNull(), eq(localizationTokenPath));
|
|
verify(delService).delete((String)isNull(), eq(localizationTokenPath));
|