-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix write stream reconnection issue (#180)
* fix: fix write stream reconnection issue * add more timeout * fix spotless * fix license check
- Loading branch information
1 parent
7f33055
commit 0e43403
Showing
4 changed files
with
184 additions
and
58 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
client-it/src/test/java/io/streamnative/oxia/client/it/ClientReconnectIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright © 2022-2024 StreamNative Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.streamnative.oxia.client.it; | ||
|
||
import io.streamnative.oxia.client.api.AsyncOxiaClient; | ||
import io.streamnative.oxia.client.api.GetResult; | ||
import io.streamnative.oxia.client.api.OxiaClientBuilder; | ||
import io.streamnative.oxia.testcontainers.OxiaContainer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.concurrent.TimeUnit; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.shaded.org.awaitility.Awaitility; | ||
|
||
@Testcontainers | ||
@Slf4j | ||
public class ClientReconnectIT { | ||
|
||
@Container | ||
private static final OxiaContainer oxia = | ||
new OxiaContainer(OxiaContainer.DEFAULT_IMAGE_NAME, 4, true) | ||
.withLogConsumer(new Slf4jLogConsumer(log)); | ||
|
||
@Test | ||
public void testReconnection() { | ||
final AsyncOxiaClient client = | ||
OxiaClientBuilder.create(oxia.getServiceAddress()).asyncClient().join(); | ||
final String key = "1"; | ||
final byte[] value = "1".getBytes(StandardCharsets.UTF_8); | ||
|
||
final long startTime = System.currentTimeMillis(); | ||
final long elapse = 3000L; | ||
while (true) { | ||
try { | ||
Thread.sleep(500); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
try { | ||
client.put(key, value).get(1, TimeUnit.SECONDS); | ||
} catch (Throwable ex) { | ||
Assertions.fail("unexpected behaviour", ex); | ||
} | ||
|
||
try { | ||
final GetResult getResult = client.get("1").get(1, TimeUnit.SECONDS); | ||
Assertions.assertArrayEquals(getResult.getValue(), value); | ||
} catch (Throwable ex) { | ||
Assertions.fail("unexpected behaviour", ex); | ||
} | ||
|
||
if (System.currentTimeMillis() - startTime >= elapse) { | ||
oxia.stop(); | ||
|
||
try { | ||
Thread.sleep(3000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
oxia.start(); | ||
|
||
Awaitility.await() | ||
.atMost(15, TimeUnit.SECONDS) | ||
.untilAsserted( | ||
() -> { | ||
try { | ||
client.put(key, value).get(1, TimeUnit.SECONDS); | ||
} catch (Throwable ex) { | ||
Assertions.fail("unexpected behaviour", ex); | ||
} | ||
|
||
try { | ||
final GetResult getResult = client.get("1").get(1, TimeUnit.SECONDS); | ||
Assertions.assertArrayEquals(getResult.getValue(), value); | ||
} catch (Throwable ex) { | ||
Assertions.fail("unexpected behaviour", ex); | ||
} | ||
}); | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters