Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/src/main/java/tech/ydb/core/impl/YdbDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ private void runDiscovery() {

private void handleThrowable(Throwable th) {
readyLock.lock();

try {
lastException = th;
scheduleNextTick();
Expand All @@ -193,16 +192,18 @@ private void handleThrowable(Throwable th) {
}

private void handleOk(String selfLocation, List<EndpointRecord> endpoints) {
readyLock.lock();
CompletableFuture<Boolean> handled = handler.handleEndpoints(endpoints, selfLocation);

readyLock.lock();
try {
isStarted = true;
lastException = null;
handler.handleEndpoints(endpoints, selfLocation).whenComplete((res, th) -> scheduleNextTick());
readyCondition.signalAll();
} finally {
readyLock.unlock();
}

handled.whenComplete((res, th) -> scheduleNextTick());
}

private static String createAddress(EndpointInfo e) {
Expand Down
40 changes: 40 additions & 0 deletions core/src/test/java/tech/ydb/core/impl/YdbDiscoveryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import io.grpc.ConnectivityState;
import io.grpc.ManagedChannel;
Expand Down Expand Up @@ -178,6 +180,44 @@ public void waitWaitingTest() {
discovery.stop();
}

@Test
public void readyOnlyAfterEndpointsAreHandledTest() throws InterruptedException {
Mockito.when(channel.newCall(Mockito.eq(DiscoveryServiceGrpc.getListEndpointsMethod()), Mockito.any()))
.thenReturn(MockedCall.discovery("self", new EndpointRecord("localhost", 12340)));

CountDownLatch handlingStarted = new CountDownLatch(1);
CountDownLatch handlingAllowed = new CountDownLatch(1);
TestHandler handler = new TestHandler() {
@Override
public CompletableFuture<Boolean> handleEndpoints(List<EndpointRecord> endpoints, String selfLocation) {
try {
handlingStarted.countDown();
Assert.assertTrue(handlingAllowed.await(1, TimeUnit.SECONDS));
return CompletableFuture.completedFuture(Boolean.TRUE);
} catch (InterruptedException ex) {
throw new AssertionError("interrupted", ex);
}
}
};

YdbDiscovery discovery = new YdbDiscovery(handler, scheduler, "/ready", Duration.ofMillis(100));
discovery.start();

// the first discovery is blocked in the endpoints handling
CompletableFuture<MockedScheduler> firstDiscovery = CompletableFuture.supplyAsync(scheduler::runNextTask);
Assert.assertTrue(handlingStarted.await(1, TimeUnit.SECONDS));

// endpoints are not applied yet, so discovery must not be ready and waiting must not be blocked
IllegalStateException ex = Assert.assertThrows(IllegalStateException.class, () -> discovery.waitReady(50));
Assert.assertEquals("Discovery is not ready", ex.getMessage());

handlingAllowed.countDown();
firstDiscovery.join();

discovery.waitReady(100);
discovery.stop();
}

@Test
public void failedDiscoveryTest() {
Mockito.when(channel.newCall(Mockito.eq(DiscoveryServiceGrpc.getListEndpointsMethod()), Mockito.any()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,20 @@ public void doubleGaugeReportsFractionalValuesAndCloses() {
}

@Test
@SuppressWarnings("deprecation")
public void legacyGaugeCreationStillReportsValues() {
meter.createLongGauge("ydb.test.legacy", null, null, m -> m.record(7));

Assert.assertEquals(7L, singleLongPoint(single("ydb.test.legacy").getLongGaugeData().getPoints()).getValue());
}

@Test
@SuppressWarnings("deprecation")
public void registrationSupportsLegacyMeterOverride() {
long[] observed = new long[1];
Meter legacy = new Meter() {
@Override
public void createLongGauge(
String name, String unit, String description, Consumer<LongMeasurement> callback) {
callback.accept((value, attrs) -> observed[0] = value);
public void createLongGauge(String name, String unit, String description, Consumer<LongMeasurement> cb) {
cb.accept((value, attrs) -> observed[0] = value);
}
};

Expand Down
Loading