mirror of https://github.com/apache/kafka.git
KAFKA-3255: Added unit tests for NetworkClient.connectionDelay(Node node, long now)
Author: Frank Scholten <frank@frankscholten.nl> Reviewers: Eno Thereska <eno.thereska@gmail.com>, Ewen Cheslack-Postava <ewen@confluent.io> Closes #941 from frankscholten/tests/cluster-connection-states
This commit is contained in:
parent
49fd0ceb09
commit
d2527af99a
|
@ -94,15 +94,6 @@ final class ClusterConnectionStates {
|
|||
return state != null && state.state == ConnectionState.CONNECTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true iff we are in the process of connecting
|
||||
* @param id The id of the connection
|
||||
*/
|
||||
public boolean isConnecting(String id) {
|
||||
NodeConnectionState state = nodeState.get(id);
|
||||
return state != null && state.state == ConnectionState.CONNECTING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter the connected state for the given connection
|
||||
* @param id The connection identifier
|
||||
|
|
|
@ -175,6 +175,35 @@ public class NetworkClientTest {
|
|||
assertEquals("There should be NO leastloadednode", leastNode, null);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectionDelay() {
|
||||
long now = time.milliseconds();
|
||||
long delay = client.connectionDelay(node, now);
|
||||
|
||||
assertEquals(0, delay);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectionDelayConnected() {
|
||||
awaitReady(client, node);
|
||||
|
||||
long now = time.milliseconds();
|
||||
long delay = client.connectionDelay(node, now);
|
||||
|
||||
assertEquals(Long.MAX_VALUE, delay);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectionDelayDisconnected() {
|
||||
awaitReady(client, node);
|
||||
|
||||
selector.close(node.idString());
|
||||
client.poll(requestTimeoutMs, time.milliseconds());
|
||||
long delay = client.connectionDelay(node, time.milliseconds());
|
||||
|
||||
assertEquals(reconnectBackoffMsTest, delay);
|
||||
}
|
||||
|
||||
private static class TestCallbackHandler implements RequestCompletionHandler {
|
||||
public boolean executed = false;
|
||||
|
|
Loading…
Reference in New Issue