HDFS-11970. Ozone: TestXceiverClientManager.testFreeByEviction fails occasionally. Contributed by Mukul Kumar Singh.
This commit is contained in:
parent
52aa60ed2f
commit
77e3bb783b
|
@ -100,15 +100,15 @@ public class XceiverClientManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Acquires a SharedXceiverClient connected to a container capable of
|
* Acquires a XceiverClientSpi connected to a container capable of
|
||||||
* storing the specified key.
|
* storing the specified key.
|
||||||
*
|
*
|
||||||
* If there is already a cached SharedXceiverClient, simply return
|
* If there is already a cached XceiverClientSpi, simply return
|
||||||
* the cached otherwise create a new one.
|
* the cached otherwise create a new one.
|
||||||
*
|
*
|
||||||
* @param pipeline the container pipeline for the client connection
|
* @param pipeline the container pipeline for the client connection
|
||||||
* @return SharedXceiverClient connected to a container
|
* @return XceiverClientSpi connected to a container
|
||||||
* @throws IOException if an SharedXceiverClient cannot be acquired
|
* @throws IOException if a XceiverClientSpi cannot be acquired
|
||||||
*/
|
*/
|
||||||
public XceiverClientSpi acquireClient(Pipeline pipeline)
|
public XceiverClientSpi acquireClient(Pipeline pipeline)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -124,7 +124,7 @@ public class XceiverClientManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Releases an SharedXceiverClient after use.
|
* Releases a XceiverClientSpi after use.
|
||||||
*
|
*
|
||||||
* @param client client to release
|
* @param client client to release
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class TestXceiverClientManager {
|
||||||
@Test
|
@Test
|
||||||
public void testFreeByReference() throws IOException {
|
public void testFreeByReference() throws IOException {
|
||||||
OzoneConfiguration conf = new OzoneConfiguration();
|
OzoneConfiguration conf = new OzoneConfiguration();
|
||||||
conf.setInt(SCM_CONTAINER_CLIENT_MAX_SIZE_KEY, 2);
|
conf.setInt(SCM_CONTAINER_CLIENT_MAX_SIZE_KEY, 1);
|
||||||
XceiverClientManager clientManager = new XceiverClientManager(conf);
|
XceiverClientManager clientManager = new XceiverClientManager(conf);
|
||||||
Cache<String, XceiverClientSpi> cache =
|
Cache<String, XceiverClientSpi> cache =
|
||||||
clientManager.getClientCache();
|
clientManager.getClientCache();
|
||||||
|
@ -118,14 +118,6 @@ public class TestXceiverClientManager {
|
||||||
client2.getPipeline().getContainerName());
|
client2.getPipeline().getContainerName());
|
||||||
Assert.assertNotEquals(client1, client2);
|
Assert.assertNotEquals(client1, client2);
|
||||||
|
|
||||||
String containerName3 = "container" + RandomStringUtils.randomNumeric(10);
|
|
||||||
Pipeline pipeline3 =
|
|
||||||
storageContainerLocationClient.allocateContainer(containerName3);
|
|
||||||
XceiverClientSpi client3 = clientManager.acquireClient(pipeline3);
|
|
||||||
Assert.assertEquals(client3.getRefcount(), 1);
|
|
||||||
Assert.assertEquals(containerName3,
|
|
||||||
client3.getPipeline().getContainerName());
|
|
||||||
|
|
||||||
// least recent container (i.e containerName1) is evicted
|
// least recent container (i.e containerName1) is evicted
|
||||||
XceiverClientSpi nonExistent1 = cache.getIfPresent(containerName1);
|
XceiverClientSpi nonExistent1 = cache.getIfPresent(containerName1);
|
||||||
Assert.assertEquals(nonExistent1, null);
|
Assert.assertEquals(nonExistent1, null);
|
||||||
|
@ -140,13 +132,12 @@ public class TestXceiverClientManager {
|
||||||
exception.expectMessage("This channel is not connected.");
|
exception.expectMessage("This channel is not connected.");
|
||||||
ContainerProtocolCalls.createContainer(client1, traceID1);
|
ContainerProtocolCalls.createContainer(client1, traceID1);
|
||||||
clientManager.releaseClient(client2);
|
clientManager.releaseClient(client2);
|
||||||
clientManager.releaseClient(client3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFreeByEviction() throws IOException {
|
public void testFreeByEviction() throws IOException {
|
||||||
OzoneConfiguration conf = new OzoneConfiguration();
|
OzoneConfiguration conf = new OzoneConfiguration();
|
||||||
conf.setInt(SCM_CONTAINER_CLIENT_MAX_SIZE_KEY, 2);
|
conf.setInt(SCM_CONTAINER_CLIENT_MAX_SIZE_KEY, 1);
|
||||||
XceiverClientManager clientManager = new XceiverClientManager(conf);
|
XceiverClientManager clientManager = new XceiverClientManager(conf);
|
||||||
Cache<String, XceiverClientSpi> cache =
|
Cache<String, XceiverClientSpi> cache =
|
||||||
clientManager.getClientCache();
|
clientManager.getClientCache();
|
||||||
|
@ -159,6 +150,9 @@ public class TestXceiverClientManager {
|
||||||
Assert.assertEquals(containerName1,
|
Assert.assertEquals(containerName1,
|
||||||
client1.getPipeline().getContainerName());
|
client1.getPipeline().getContainerName());
|
||||||
|
|
||||||
|
clientManager.releaseClient(client1);
|
||||||
|
Assert.assertEquals(client1.getRefcount(), 0);
|
||||||
|
|
||||||
String containerName2 = "container" + RandomStringUtils.randomNumeric(10);
|
String containerName2 = "container" + RandomStringUtils.randomNumeric(10);
|
||||||
Pipeline pipeline2 =
|
Pipeline pipeline2 =
|
||||||
storageContainerLocationClient.allocateContainer(containerName2);
|
storageContainerLocationClient.allocateContainer(containerName2);
|
||||||
|
@ -168,16 +162,6 @@ public class TestXceiverClientManager {
|
||||||
client2.getPipeline().getContainerName());
|
client2.getPipeline().getContainerName());
|
||||||
Assert.assertNotEquals(client1, client2);
|
Assert.assertNotEquals(client1, client2);
|
||||||
|
|
||||||
clientManager.releaseClient(client1);
|
|
||||||
Assert.assertEquals(client1.getRefcount(), 0);
|
|
||||||
|
|
||||||
String containerName3 = "container" + RandomStringUtils.randomNumeric(10);
|
|
||||||
Pipeline pipeline3 =
|
|
||||||
storageContainerLocationClient.allocateContainer(containerName3);
|
|
||||||
XceiverClientSpi client3 = clientManager.acquireClient(pipeline3);
|
|
||||||
Assert.assertEquals(client3.getRefcount(), 1);
|
|
||||||
Assert.assertEquals(containerName3,
|
|
||||||
client3.getPipeline().getContainerName());
|
|
||||||
|
|
||||||
// now client 1 should be evicted
|
// now client 1 should be evicted
|
||||||
XceiverClientSpi nonExistent = cache.getIfPresent(containerName1);
|
XceiverClientSpi nonExistent = cache.getIfPresent(containerName1);
|
||||||
|
@ -189,6 +173,5 @@ public class TestXceiverClientManager {
|
||||||
exception.expectMessage("This channel is not connected.");
|
exception.expectMessage("This channel is not connected.");
|
||||||
ContainerProtocolCalls.createContainer(client1, traceID2);
|
ContainerProtocolCalls.createContainer(client1, traceID2);
|
||||||
clientManager.releaseClient(client2);
|
clientManager.releaseClient(client2);
|
||||||
clientManager.releaseClient(client3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue