Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-20545 Improve logging in AbstractRpcTest #2717

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

/**
* Marshaller.
* TODO: Reuse this code in ignite-schema module (IGNITE-16088).
*/
public abstract class Marshaller {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@

package org.apache.ignite.raft.jraft.rpc;

import static java.util.stream.Collectors.toList;
import static org.apache.ignite.raft.jraft.test.TestUtils.INIT_PORT;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.ignite.internal.logger.IgniteLogger;
import org.apache.ignite.internal.logger.Loggers;
import org.apache.ignite.network.ClusterNode;
import org.apache.ignite.network.ClusterService;
import org.apache.ignite.network.NetworkAddress;
import org.apache.ignite.network.StaticNodeFinder;
Expand All @@ -40,6 +45,8 @@
* Ignite RPC test.
*/
public class IgniteRpcTest extends AbstractRpcTest {
private static final IgniteLogger LOG = Loggers.forClass(IgniteRpcTest.class);

/** The counter. */
private final AtomicInteger cntr = new AtomicInteger();

Expand All @@ -54,16 +61,13 @@ public IgniteRpcTest(TestInfo testInfo) {
this.testInfo = testInfo;
}

/** {@inheritDoc} */
@AfterEach
@Override public void tearDown() {
super.tearDown();

public void shutdownExecutor() {
ExecutorServiceHelper.shutdownAndAwaitTermination(requestExecutor);
}

/** {@inheritDoc} */
@Override public RpcServer<?> createServer() {
@Override
public RpcServer<?> createServer() {
ClusterService service = ClusterServiceTestUtils.clusterService(
testInfo,
INIT_PORT,
Expand All @@ -87,8 +91,8 @@ public IgniteRpcTest(TestInfo testInfo) {
return server;
}

/** {@inheritDoc} */
@Override public RpcClient createClient0() {
@Override
public RpcClient createClient0() {
int i = cntr.incrementAndGet();

ClusterService service = ClusterServiceTestUtils.clusterService(
Expand All @@ -112,38 +116,23 @@ public IgniteRpcTest(TestInfo testInfo) {
return client;
}

/** {@inheritDoc} */
@Override protected boolean waitForTopology(RpcClient client, int expected, long timeout) {
IgniteRpcClient client0 = (IgniteRpcClient) client;

ClusterService service = client0.clusterService();
@Override
protected boolean waitForTopology(RpcClient client, int expected, long timeout) {
ClusterService service = ((IgniteRpcClient) client).clusterService();

return waitForTopology(service, expected, timeout);
}
boolean success = TestUtils.waitForTopology(service, expected, timeout);

/**
* Waits for the cluster's topology to have the expected count of nodes.
*
* @param service The service.
* @param expected Expected count.
* @param timeout The timeout.
* @return Wait status.
*/
protected boolean waitForTopology(ClusterService service, int expected, long timeout) {
long stop = System.currentTimeMillis() + timeout;

while (System.currentTimeMillis() < stop) {
if (service.topologyService().allMembers().size() == expected) {
return true;
}
if (!success) {
Collection<ClusterNode> topology = service.topologyService().allMembers();

try {
Thread.sleep(50);
} catch (InterruptedException e) {
return false;
}
LOG.error("Topology on node '{}' didn't match expected topology size. Expected: {}, actual: {}.\nTopology nodes: {}",
service.nodeName(),
expected,
topology.size(),
topology.stream().map(ClusterNode::name).collect(toList())
);
}

return false;
return success;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static byte[] getRandomBytes() {
* @param timeout The timeout in millis.
* @return {@code True} if topology size is equal to expected.
*/
public static boolean waitForTopology(ClusterService cluster, int expected, int timeout) {
public static boolean waitForTopology(ClusterService cluster, int expected, long timeout) {
return waitForCondition(() -> cluster.topologyService().allMembers().size() >= expected, timeout);
}

Expand Down