Skip to content

Commit a41d204

Browse files
committed
chore: some code smells
Signed-off-by: iGxnon <[email protected]>
1 parent 79ea74b commit a41d204

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

jxline-core/src/main/java/cloud/xline/jxline/impl/ProtocolClientImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ int recoverQuorum(int size) {
252252
return quorum(size) / 2 + 1;
253253
}
254254

255+
static final int RETRY_TIMEOUT = 3;
256+
static final int RETRY_LIMIT = 5;
257+
258+
// TODO: Need to be refactored within retry policy...
255259
State getInitState() {
256260
ManagedChannel initChannel = this.connectionManager().getInitChannel();
257261
VertxProtocolGrpc.ProtocolVertxStub initStub = VertxProtocolGrpc.newVertxStub(initChannel);
@@ -261,11 +265,13 @@ State getInitState() {
261265
int retries = -1;
262266
do {
263267
retries++;
264-
if (retries > 5) {
268+
if (retries > RETRY_LIMIT) {
265269
throw new RuntimeException("connection failed");
266270
}
267271
try {
268-
response = completable(initStub.fetchCluster(request)).get(3, TimeUnit.SECONDS);
272+
response =
273+
completable(initStub.fetchCluster(request))
274+
.get(RETRY_TIMEOUT, TimeUnit.SECONDS);
269275
} catch (Exception e) {
270276
logger().warn("fetch cluster failed, " + e);
271277
}

jxline-core/src/test/java/ProtocolTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
import org.junit.jupiter.api.BeforeAll;
66
import org.junit.jupiter.api.Test;
77
import org.junit.jupiter.api.Timeout;
8+
89
import static org.assertj.core.api.Assertions.*;
910

1011
@Timeout(value = 20)
1112
public class ProtocolTest {
1213
static ProtocolClient client;
1314

15+
static String INIT_ENDPOINT = "http://172.20.0.5:2379";
16+
1417
@BeforeAll
1518
static void onConnect() {
16-
client = Client.builder().endpoints("http://172.20.0.5:2379").build().getProtocolClient();
19+
client = Client.builder().endpoints(INIT_ENDPOINT).build().getProtocolClient();
1720
}
1821

1922
@Test

0 commit comments

Comments
 (0)