HDDS-1332. Attempt to fix flaky test testStartStopDatanodeStateMachine (#697)

This commit is contained in:
Doroszlai, Attila 2019-04-05 22:21:58 +02:00 committed by Arpit Agarwal
parent 26dc940813
commit 274ab4e86c
2 changed files with 11 additions and 10 deletions

View File

@ -35,13 +35,13 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import static java.util.Collections.unmodifiableList;
import static org.apache.hadoop.hdds.scm.HddsServerUtil
.getScmRpcTimeOutInMilliseconds;
@ -184,7 +184,12 @@ public class SCMConnectionManager
* @return - List of RPC Endpoints.
*/
public Collection<EndpointStateMachine> getValues() {
return scmMachines.values();
readLock();
try {
return unmodifiableList(new ArrayList<>(scmMachines.values()));
} finally {
readUnlock();
}
}
@Override
@ -201,9 +206,7 @@ public class SCMConnectionManager
public List<EndpointStateMachineMBean> getSCMServers() {
readLock();
try {
return Collections
.unmodifiableList(new ArrayList<>(scmMachines.values()));
return unmodifiableList(new ArrayList<>(scmMachines.values()));
} finally {
readUnlock();
}

View File

@ -154,8 +154,6 @@ public class TestDatanodeStateMachine {
/**
* Assert that starting statemachine executes the Init State.
*
* @throws InterruptedException
*/
@Test
public void testStartStopDatanodeStateMachine() throws IOException,
@ -167,9 +165,9 @@ public class TestDatanodeStateMachine {
stateMachine.getConnectionManager();
GenericTestUtils.waitFor(
() -> {
LOG.info("connectionManager.getValues().size() is {}",
connectionManager.getValues().size());
return connectionManager.getValues().size() == 1;
int size = connectionManager.getValues().size();
LOG.info("connectionManager.getValues().size() is {}", size);
return size == 1;
}, 1000, 30000);
stateMachine.stopDaemon();