From 72ce91bc3eaa15db716aea1a8f9469ced008786c Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Mon, 11 Aug 2025 18:34:37 +0530 Subject: [PATCH] Created dummy java test to check blocking method behaviour in liveobjects --- live-objects/build.gradle.kts | 8 +++ .../objects/integration/java/LiveMapTest.java | 51 +++++++++++++++++++ .../integration/setup/IntegrationTest.kt | 4 ++ 3 files changed, 63 insertions(+) create mode 100644 live-objects/src/test/kotlin/io/ably/lib/objects/integration/java/LiveMapTest.java diff --git a/live-objects/build.gradle.kts b/live-objects/build.gradle.kts index e4219840d..1e83204d2 100644 --- a/live-objects/build.gradle.kts +++ b/live-objects/build.gradle.kts @@ -10,6 +10,14 @@ repositories { mavenCentral() } +sourceSets { + test { + java { + srcDirs("src/test/kotlin/") + } + } +} + dependencies { implementation(project(":java")) implementation(libs.bundles.common) diff --git a/live-objects/src/test/kotlin/io/ably/lib/objects/integration/java/LiveMapTest.java b/live-objects/src/test/kotlin/io/ably/lib/objects/integration/java/LiveMapTest.java new file mode 100644 index 000000000..f32ab9293 --- /dev/null +++ b/live-objects/src/test/kotlin/io/ably/lib/objects/integration/java/LiveMapTest.java @@ -0,0 +1,51 @@ +package io.ably.lib.objects.integration.java; + +import io.ably.lib.objects.LiveObjects; +import io.ably.lib.objects.integration.setup.IntegrationTest; +import io.ably.lib.objects.type.counter.LiveCounter; +import io.ably.lib.objects.type.map.LiveMap; +import io.ably.lib.realtime.ChannelBase; +import io.ably.lib.realtime.CompletionListener; +import io.ably.lib.types.AblyException; +import io.ably.lib.types.ErrorInfo; +import org.junit.Test; + +import static java.lang.Thread.sleep; +import static org.junit.Assert.assertNotNull; + +public class LiveMapTest extends IntegrationTest { + + @Test + public void testLiveMapFunctionality() throws AblyException, InterruptedException { + String channelName = this.generateChannelName$live_objects_test(); + ChannelBase channel = this.getRealtimeChannel$live_objects_test(channelName); + assertNotNull("Channel name should not be null", channel); + channel.attach(new CompletionListener() { + @Override + public void onSuccess() { + LiveObjects objects = null; + try { + objects = channel.getObjects(); + } catch (AblyException e) { + throw new RuntimeException(e); + } + // Won't be able to receive sync message because + // attach callback is blocked by getRoot -> internally blocks eventloop that processes incoming messages + LiveMap root = objects.getRoot(); // getRoot keeps waiting for object sync message indefinitely + System.out.println("LiveMap root: " + root); + + // Won't be able to receive newly created map/counter message + LiveMap newMap = objects.createMap(); // blocks eventloop, keeps waiting indefinitely for publish ack + System.out.println("New LiveMap created: " + newMap); + LiveCounter counter = objects.createCounter(); // blocks eventloop, keeps waiting indefinitely for publish ack + System.out.println("New LiveCounter created: " + counter); + } + + @Override + public void onError(ErrorInfo reason) { + + } + }); + sleep(10000); + } +} diff --git a/live-objects/src/test/kotlin/io/ably/lib/objects/integration/setup/IntegrationTest.kt b/live-objects/src/test/kotlin/io/ably/lib/objects/integration/setup/IntegrationTest.kt index dd3f41a59..cd84a17ab 100644 --- a/live-objects/src/test/kotlin/io/ably/lib/objects/integration/setup/IntegrationTest.kt +++ b/live-objects/src/test/kotlin/io/ably/lib/objects/integration/setup/IntegrationTest.kt @@ -49,6 +49,10 @@ abstract class IntegrationTest { return client.channels.get(channelName, channelOpts) } + internal fun getRealtimeChannel(channelName: String): Channel { + return runBlocking { getRealtimeChannel(channelName, "client1") } + } + /** * Generates a unique channel name for testing purposes. * This is mainly to avoid channel name/state/history collisions across tests in same file.