String result = this.manager.locate(sessionId);
assertSame(expected, result);
// Test rehash in progress
DistributionManager distManager = mock(DistributionManager.class);
when(this.cache.getAdvancedCache()).thenReturn(this.cache);
when(this.cache.getDistributionManager()).thenReturn(distManager);
when(distManager.getLocality(sessionId)).thenReturn(DataLocality.NOT_LOCAL_UNCERTAIN);
when(this.sessionManager.getJvmRoute()).thenReturn(expected);
result = this.manager.locate(sessionId);
assertSame(expected, result);
// Test session hashes locally
EmbeddedCacheManager container = mock(EmbeddedCacheManager.class);
Address address1 = mock(Address.class);
Address address2 = mock(Address.class);
Address localAddress = mock(Address.class);
List<Address> addresses = Arrays.asList(address1, address2, localAddress);
when(this.cache.getAdvancedCache()).thenReturn(this.cache);
when(this.cache.getDistributionManager()).thenReturn(distManager);
when(distManager.getLocality(sessionId)).thenReturn(DataLocality.LOCAL);
when(distManager.locate(same(sessionId))).thenReturn(addresses);
when(this.cache.getCacheManager()).thenReturn(container);
when(container.getAddress()).thenReturn(address2);
when(this.sessionManager.getJvmRoute()).thenReturn(expected);
result = this.manager.locate(sessionId);
assertSame(expected, result);
// Test session does not hash locally
addresses = Arrays.asList(address1, address2);
ArgumentCaptor<Address> capturedAddress = ArgumentCaptor.forClass(Address.class);
when(this.cache.getAdvancedCache()).thenReturn(this.cache);
when(this.cache.getDistributionManager()).thenReturn(distManager);
when(distManager.getLocality(sessionId)).thenReturn(DataLocality.NOT_LOCAL);
when(distManager.locate(same(sessionId))).thenReturn(addresses);
when(this.cache.getCacheManager()).thenReturn(container);
when(container.getAddress()).thenReturn(localAddress);
when(this.registry.getRemoteEntry(capturedAddress.capture())).thenReturn(new AbstractMap.SimpleImmutableEntry<String, Void>(expected, null));
when(this.cache.withFlags(Flag.FORCE_SYNCHRONOUS)).thenReturn(this.cache);