Skip to content
Closed
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
8 changes: 8 additions & 0 deletions live-objects/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ repositories {
mavenCentral()
}

sourceSets {
test {
java {
srcDirs("src/test/kotlin/")
}
}
}

dependencies {
implementation(project(":java"))
implementation(libs.bundles.common)
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading