-
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.
feat(notification): support deleteRange notification (#187)
* format license * feat(notification): support disable notification
- Loading branch information
1 parent
cce083a
commit a86d398
Showing
4 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
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
114 changes: 114 additions & 0 deletions
114
client-it/src/test/java/io/streamnative/oxia/client/it/NotificationIt.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,114 @@ | ||
/* | ||
* 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.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.sdk.OpenTelemetrySdk; | ||
import io.opentelemetry.sdk.metrics.SdkMeterProvider; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; | ||
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; | ||
import io.streamnative.oxia.client.api.AsyncOxiaClient; | ||
import io.streamnative.oxia.client.api.Notification; | ||
import io.streamnative.oxia.client.api.OxiaClientBuilder; | ||
import io.streamnative.oxia.testcontainers.OxiaContainer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Queue; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.awaitility.Awaitility; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.images.PullPolicy; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
@Testcontainers | ||
@Slf4j | ||
public class NotificationIt { | ||
@Container | ||
private static final OxiaContainer oxia = | ||
new OxiaContainer(OxiaContainer.DEFAULT_IMAGE_NAME) | ||
.withImagePullPolicy(PullPolicy.alwaysPull()) | ||
.withShards(10) | ||
.withLogConsumer(new Slf4jLogConsumer(log)); | ||
|
||
private static AsyncOxiaClient client; | ||
|
||
private static Queue<Notification> notifications = new LinkedBlockingQueue<>(); | ||
|
||
private static InMemoryMetricReader metricReader; | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
Resource resource = | ||
Resource.getDefault() | ||
.merge( | ||
Resource.create( | ||
Attributes.of(ResourceAttributes.SERVICE_NAME, "logical-service-name"))); | ||
|
||
metricReader = InMemoryMetricReader.create(); | ||
SdkMeterProvider sdkMeterProvider = | ||
SdkMeterProvider.builder().registerMetricReader(metricReader).setResource(resource).build(); | ||
|
||
OpenTelemetry openTelemetry = | ||
OpenTelemetrySdk.builder().setMeterProvider(sdkMeterProvider).build(); | ||
|
||
client = | ||
OxiaClientBuilder.create(oxia.getServiceAddress()) | ||
.openTelemetry(openTelemetry) | ||
.asyncClient() | ||
.join(); | ||
client.notifications(notifications::add); | ||
} | ||
|
||
@AfterAll | ||
static void afterAll() throws Exception { | ||
if (client != null) { | ||
client.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testDeleteRange() { | ||
|
||
for (int i = 0; i < 10; i++) { | ||
client.put(i + "", (i + "").getBytes(StandardCharsets.UTF_8)).join(); | ||
} | ||
|
||
Awaitility.await().untilAsserted(() -> Assertions.assertEquals(notifications.size(), 10)); | ||
|
||
notifications.clear(); | ||
|
||
client.deleteRange("0", "100").join(); | ||
|
||
Awaitility.await() | ||
.untilAsserted( | ||
() -> { | ||
Assertions.assertEquals(notifications.size(), 10); // 10 shards | ||
for (Notification notification : notifications) { | ||
Assertions.assertInstanceOf(Notification.KeyRangeDelete.class, notification); | ||
final Notification.KeyRangeDelete krd = (Notification.KeyRangeDelete) notification; | ||
Assertions.assertEquals(krd.startKeyInclusive(), "0"); | ||
Assertions.assertEquals(krd.endKeyExclusive(), "100"); | ||
} | ||
}); | ||
} | ||
} |
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