Skip to content

Commit

Permalink
azure-messaging-webpubsub-client, test setup with azure-messaging-web…
Browse files Browse the repository at this point in the history
…pubsub endpoint (Azure#40726)
  • Loading branch information
weidongxu-microsoft authored Jun 28, 2024
1 parent 3afdb70 commit cde7e0e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.azure.messaging.webpubsub.client;

import com.azure.core.test.annotation.DoNotRecord;
import com.azure.core.test.annotation.LiveOnly;
import com.azure.core.util.BinaryData;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
Expand Down Expand Up @@ -36,7 +36,7 @@
public class ClientTests extends TestBase {

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testClientState() {
WebPubSubAsyncClient asyncClient = getClientBuilder().buildAsyncClient();

Expand All @@ -59,7 +59,7 @@ public void testClientState() {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testTwoClients() throws InterruptedException {
String groupName = "testTwoClients";
CountDownLatch latch = new CountDownLatch(1);
Expand Down Expand Up @@ -90,7 +90,7 @@ public void testTwoClients() throws InterruptedException {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testClientCloseable() {
CountDownLatch connectedLatch = new CountDownLatch(1);
CountDownLatch stoppedLatch = new CountDownLatch(1);
Expand Down Expand Up @@ -120,7 +120,7 @@ public void testClientCloseable() {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testStopAndStart() throws InterruptedException {
String groupName = "testStopAndStart";
CountDownLatch latch1 = new CountDownLatch(1);
Expand Down Expand Up @@ -167,7 +167,7 @@ public void testStopAndStart() throws InterruptedException {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testConcurrentStop() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(2);

Expand Down Expand Up @@ -199,7 +199,7 @@ public void testConcurrentStop() throws InterruptedException {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testStopWhenStopped() {
WebPubSubClient client = getClientBuilder()
.buildClient();
Expand All @@ -208,7 +208,7 @@ public void testStopWhenStopped() {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testStopBeforeConnected() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);

Expand All @@ -231,13 +231,13 @@ public void testStopBeforeConnected() throws InterruptedException {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testNoCredential() {
Assertions.assertThrows(IllegalStateException.class, () -> new WebPubSubClientBuilder().buildClient());
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testBothCredential() {
Assertions.assertThrows(IllegalStateException.class, () -> new WebPubSubClientBuilder()
.credential(new WebPubSubClientCredential(() -> "mock"))
Expand All @@ -246,7 +246,7 @@ public void testBothCredential() {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testInvalidCredential() {
WebPubSubServiceAsyncClient client = new WebPubSubServiceClientBuilder()
.connectionString(Configuration.getGlobalConfiguration().get("CONNECTION_STRING"))
Expand Down Expand Up @@ -280,7 +280,7 @@ public void testInvalidCredential() {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testClientEvents() throws InterruptedException {
CountDownLatch connectedLatch = new CountDownLatch(1);
CountDownLatch stoppedLatch = new CountDownLatch(1);
Expand Down Expand Up @@ -317,7 +317,7 @@ public void testClientEvents() throws InterruptedException {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testClientListener() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);

Expand Down Expand Up @@ -358,7 +358,7 @@ public void testClientListener() throws InterruptedException {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testConnectedDisconnectedEvent() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
List<String> eventReceived = new ArrayList<>();
Expand All @@ -381,7 +381,7 @@ public void testConnectedDisconnectedEvent() throws InterruptedException {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testServerDisconnectedOnInvalidPayload() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
List<String> eventReceived = new ArrayList<>();
Expand Down Expand Up @@ -410,7 +410,7 @@ public void testServerDisconnectedOnInvalidPayload() throws InterruptedException
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testClientRecoveryOnSocketClose() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
List<String> eventReceived = new ArrayList<>();
Expand Down Expand Up @@ -449,7 +449,7 @@ public void testClientRecoveryOnSocketClose() throws InterruptedException {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testClientReconnectOnSocketClose() throws InterruptedException {
String groupName = "testClientReconnectOnSocketClose";
CountDownLatch latch = new CountDownLatch(1);
Expand Down Expand Up @@ -499,7 +499,7 @@ public void testClientReconnectOnSocketClose() throws InterruptedException {


@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testClientStopOnSocketClose() throws InterruptedException {
String groupName = "testClientStopOnSocketClose";
CountDownLatch latch = new CountDownLatch(1);
Expand Down Expand Up @@ -535,7 +535,7 @@ public void testClientStopOnSocketClose() throws InterruptedException {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testStartInStoppedEvent() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);

Expand All @@ -559,7 +559,7 @@ public void testStartInStoppedEvent() throws InterruptedException {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testProtocol() {
WebPubSubClient client = getClientBuilder()
.protocol(WebPubSubProtocolType.JSON_PROTOCOL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.azure.messaging.webpubsub.client;

import com.azure.core.test.annotation.DoNotRecord;
import com.azure.core.test.annotation.LiveOnly;
import com.azure.core.util.BinaryData;
import com.azure.messaging.webpubsub.client.models.SendEventOptions;
import com.azure.messaging.webpubsub.client.models.WebPubSubDataFormat;
Expand All @@ -21,7 +21,7 @@ public class EventTests extends TestBase {

@Disabled("Require event handler configured in Azure")
@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testSendEvent() {
WebPubSubClient client = getClient();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.azure.messaging.webpubsub.client;

import com.azure.core.test.annotation.DoNotRecord;
import com.azure.core.test.annotation.LiveOnly;
import com.azure.core.util.BinaryData;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.logging.LogLevel;
Expand All @@ -30,15 +30,15 @@ public class GroupMessageTests extends TestBase {
private static final String HELLO = "hello";

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testSendMessageBeforeStart() {
WebPubSubClient client = getClient();
Assertions.assertThrows(SendMessageFailedException.class,
() -> client.sendToGroup("testSendMessageBeforeStart", HELLO));
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testSendMessage() {
String groupName = "testSendMessage";
WebPubSubClient client = getClient();
Expand All @@ -58,7 +58,7 @@ public void testSendMessage() {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testSendMessageFireAndForget() {
String groupName = "testSendMessageFireAndForget";
WebPubSubClient client = getClient();
Expand All @@ -75,7 +75,7 @@ public void testSendMessageFireAndForget() {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testSendJsonMessage() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
BinaryData[] data = new BinaryData[1];
Expand Down Expand Up @@ -109,7 +109,7 @@ public void testSendJsonMessage() throws InterruptedException {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testSendBinaryMessage() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
BinaryData[] data = new BinaryData[1];
Expand Down Expand Up @@ -140,7 +140,7 @@ public void testSendBinaryMessage() throws InterruptedException {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testSendDuplicateMessage() {
String groupName = "testSendDuplicateMessage";
WebPubSubClient client = getClient();
Expand All @@ -161,7 +161,7 @@ public void testSendDuplicateMessage() {

@Disabled("Performance test")
@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testSendMessagePerformance() throws InterruptedException {
final int count = 1000;
CountDownLatch latch = new CountDownLatch(count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

package com.azure.messaging.webpubsub.client;

import com.azure.core.test.annotation.DoNotRecord;
import com.azure.core.test.annotation.LiveOnly;
import org.junit.jupiter.api.Test;

public class GroupTests extends TestBase {

private static final String GROUP = "group";

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testJoinLeaveGroup() {
WebPubSubClient client = getClient();
try {
Expand All @@ -26,7 +26,7 @@ public void testJoinLeaveGroup() {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testLeaveGroupBeforeJoin() {
WebPubSubClient client = getClient();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.azure.messaging.webpubsub.client;

import com.azure.core.test.annotation.DoNotRecord;
import com.azure.core.test.annotation.LiveOnly;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

Expand All @@ -16,7 +16,7 @@ public class SequenceAckTests extends TestBase {
// we may want to add a message interceptor to client to inspect the wire messages

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testNewSequenceIdAfterStop() {
String groupName = "testNewSequenceIdAfterStop";

Expand Down Expand Up @@ -46,7 +46,7 @@ public void testNewSequenceIdAfterStop() {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testContinuedSequenceIdAfterRecover() {
String groupName = "testContinuedSequenceIdAfterRecover";

Expand All @@ -73,7 +73,7 @@ public void testContinuedSequenceIdAfterRecover() {
}

@Test
@DoNotRecord(skipInPlayback = true)
@LiveOnly
public void testNewSequenceIdAfterReconnect() {
String groupName = "testNewSequenceIdAfterReconnect";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.azure.messaging.webpubsub.client;

import com.azure.core.util.Configuration;
import com.azure.identity.AzurePowerShellCredentialBuilder;
import com.azure.messaging.webpubsub.WebPubSubServiceClient;
import com.azure.messaging.webpubsub.WebPubSubServiceClientBuilder;
import com.azure.messaging.webpubsub.client.implementation.WebPubSubClientState;
Expand All @@ -13,15 +14,23 @@

import java.time.Duration;

/**
* Required environment variable for LIVE test:
* - WEB_PUB_SUB_ENDPOINT: endpoint of the Web PubSub Service
*/
public class TestBase extends com.azure.core.test.TestBase {

protected static WebPubSubClientBuilder getClientBuilder() {
return getClientBuilder("user1");
}

protected static WebPubSubClientBuilder getClientBuilder(String userId) {
WebPubSubServiceClient client = new WebPubSubServiceClientBuilder().connectionString(
Configuration.getGlobalConfiguration().get("CONNECTION_STRING")).hub("hub1").buildClient();
WebPubSubServiceClient client = new WebPubSubServiceClientBuilder()
.endpoint(Configuration.getGlobalConfiguration().get(
"WEB_PUB_SUB_ENDPOINT"))
.credential(new AzurePowerShellCredentialBuilder().build())
.hub("hub1")
.buildClient();

// client builder
return new WebPubSubClientBuilder().credential(new WebPubSubClientCredential(() -> client.getClientAccessToken(
Expand Down

0 comments on commit cde7e0e

Please sign in to comment.