Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add digital twins test for pagination of event routes #15869

Merged
merged 3 commits into from
Oct 1, 2020
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
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package com.azure.digitaltwins.core;

import com.azure.core.http.HttpClient;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.util.logging.ClientLogger;
import com.azure.digitaltwins.core.models.EventRoute;
import com.azure.digitaltwins.core.models.EventRoutesListOptions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;

import java.net.HttpURLConnection;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import static com.azure.digitaltwins.core.TestHelper.DISPLAY_NAME_WITH_ARGUMENTS;
import static com.azure.digitaltwins.core.TestHelper.assertRestException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Tests for the async client's event route APIs
Expand Down Expand Up @@ -81,4 +88,40 @@ public void createEventRouteThrowsIfFilterIsMalformed(HttpClient httpClient, Dig
StepVerifier.create(asyncClient.createEventRoute(eventRouteId, eventRouteToCreate))
.verifyErrorSatisfies(ex -> assertRestException(ex, HttpURLConnection.HTTP_BAD_REQUEST));
}

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.digitaltwins.core.TestHelper#getTestParameters")
@Override
public void listEventRoutesPaginationWorks(HttpClient httpClient, DigitalTwinsServiceVersion serviceVersion) {
DigitalTwinsAsyncClient asyncClient = getAsyncClient(httpClient, serviceVersion);
final int eventRouteCountToCreate = 5;
final int expectedPageSize = 2;

// create enough event routes so that the list API can have multiple pages
for (int i = 0; i < eventRouteCountToCreate; i++) {
String eventRouteId = testResourceNamer.randomUuid();
EventRoute eventRouteToCreate = new EventRoute(EVENT_ROUTE_ENDPOINT_NAME);
eventRouteToCreate.setFilter(FILTER);
StepVerifier.create(asyncClient.createEventRoute(eventRouteId, eventRouteToCreate))
.verifyComplete();
}

// list event routes by page, make sure that all non-final pages have the expected page size
AtomicInteger pageCount = new AtomicInteger(0);
EventRoutesListOptions eventRoutesListOptions = (new EventRoutesListOptions()).setMaxItemCount(expectedPageSize);
StepVerifier.create(asyncClient.listEventRoutes(eventRoutesListOptions).byPage())
.thenConsumeWhile(
(pagedResponseOfEventRoute) -> pagedResponseOfEventRoute != null,
(pagedResponseOfEventRoute) -> {
pageCount.incrementAndGet();

// Any page of results with a continuation token should be a non-final page, and should have the exact page size that we specified above
if (pagedResponseOfEventRoute.getContinuationToken() != null) {
assertEquals(expectedPageSize, pagedResponseOfEventRoute.getValue().size());
}
})
.verifyComplete();

assertTrue(pageCount.get() >= 3, "At least three pages should have been returned.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

import com.azure.core.http.HttpClient;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
import com.azure.digitaltwins.core.models.EventRoute;
import com.azure.digitaltwins.core.models.EventRoutesListOptions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.net.HttpURLConnection;

import static com.azure.digitaltwins.core.TestHelper.DISPLAY_NAME_WITH_ARGUMENTS;
import static com.azure.digitaltwins.core.TestHelper.assertRestException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Tests for the sync client's event route APIs
Expand Down Expand Up @@ -75,4 +80,37 @@ public void createEventRouteThrowsIfFilterIsMalformed(HttpClient httpClient, Dig

assertRestException(() -> client.createEventRoute(eventRouteId, eventRouteToCreate), HttpURLConnection.HTTP_BAD_REQUEST);
}

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.digitaltwins.core.TestHelper#getTestParameters")
@Override
public void listEventRoutesPaginationWorks(HttpClient httpClient, DigitalTwinsServiceVersion serviceVersion) {
DigitalTwinsClient client = getClient(httpClient, serviceVersion);
final int eventRouteCountToCreate = 5;
final int expectedPageSize = 2;

// create enough event routes so that the list API can have multiple pages
for (int i = 0; i < eventRouteCountToCreate; i++) {
String eventRouteId = testResourceNamer.randomUuid();
EventRoute eventRouteToCreate = new EventRoute(EVENT_ROUTE_ENDPOINT_NAME);
eventRouteToCreate.setFilter(FILTER);
client.createEventRoute(eventRouteId, eventRouteToCreate);
}

// list event routes by page, make sure that all non-final pages have the expected page size
EventRoutesListOptions eventRoutesListOptions = (new EventRoutesListOptions()).setMaxItemCount(expectedPageSize);
PagedIterable<EventRoute> eventRoutes = client.listEventRoutes(eventRoutesListOptions, Context.NONE);
Iterable<PagedResponse<EventRoute>> eventRoutePages = eventRoutes.iterableByPage();
int pageCount = 0;
for (PagedResponse<EventRoute> eventRoutePagedResponse : eventRoutePages) {
pageCount++;

// Any page of results with a continuation token should be a non-final page, and should have the exact page size that we specified above
if (eventRoutePagedResponse.getContinuationToken() != null) {
assertEquals(expectedPageSize, eventRoutePagedResponse.getValue().size());
}
}

assertTrue(pageCount >= 3, "At least three pages should have been returned.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public abstract class EventRoutesTestBase extends DigitalTwinsTestBase {
@Test
public abstract void createEventRouteThrowsIfFilterIsMalformed(HttpClient httpClient, DigitalTwinsServiceVersion serviceVersion);

@Test
public abstract void listEventRoutesPaginationWorks(HttpClient httpClient, DigitalTwinsServiceVersion serviceVersion);

// Azure Digital Twins instances have a low cap on the number of event routes allowed, so we need to delete the existing
// event routes before each test to make sure that we can add an event route in each test.
@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"networkCallRecords" : [ {
"Method" : "GET",
"Uri" : "https://REDACTED.api.wus2.digitaltwins.azure.net/eventroutes?api-version=2020-05-31-preview",
"Headers" : {
"User-Agent" : "azsdk-java-azure-digitaltwins-core/1.0.0-beta.3 (11.0.8; Windows 10; 10.0)",
"x-ms-client-request-id" : "fc4f1981-f140-4a5a-a9bf-0f6cdbcdd515"
},
"Response" : {
"Strict-Transport-Security" : "max-age=2592000",
"retry-after" : "0",
"Content-Length" : "28",
"StatusCode" : "200",
"Body" : "{\"value\":[],\"nextLink\":null}",
"Date" : "Thu, 01 Oct 2020 21:29:28 GMT",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.api.wus2.digitaltwins.azure.net/eventroutes/860ec2a5-ade0-4d0c-9545-0bb533b91eb0?api-version=2020-05-31-preview",
"Headers" : {
"User-Agent" : "azsdk-java-azure-digitaltwins-core/1.0.0-beta.3 (11.0.8; Windows 10; 10.0)",
"x-ms-client-request-id" : "66026f8b-b1fc-4278-a452-82387d6b90a4",
"Content-Type" : "application/json"
},
"Response" : {
"Strict-Transport-Security" : "max-age=2592000",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "204",
"Date" : "Thu, 01 Oct 2020 21:29:29 GMT"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.api.wus2.digitaltwins.azure.net/eventroutes/0ca3d236-73fb-4de1-964a-361bc37d8682?api-version=2020-05-31-preview",
"Headers" : {
"User-Agent" : "azsdk-java-azure-digitaltwins-core/1.0.0-beta.3 (11.0.8; Windows 10; 10.0)",
"x-ms-client-request-id" : "76394e83-387e-4d09-84c8-41667a94681e",
"Content-Type" : "application/json"
},
"Response" : {
"Strict-Transport-Security" : "max-age=2592000",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "204",
"Date" : "Thu, 01 Oct 2020 21:29:29 GMT"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.api.wus2.digitaltwins.azure.net/eventroutes/245740f0-9508-4fb6-90a3-2dc1acadcc4f?api-version=2020-05-31-preview",
"Headers" : {
"User-Agent" : "azsdk-java-azure-digitaltwins-core/1.0.0-beta.3 (11.0.8; Windows 10; 10.0)",
"x-ms-client-request-id" : "4414bd90-7e81-414b-87d0-597cf8d16ddf",
"Content-Type" : "application/json"
},
"Response" : {
"Strict-Transport-Security" : "max-age=2592000",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "204",
"Date" : "Thu, 01 Oct 2020 21:29:29 GMT"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.api.wus2.digitaltwins.azure.net/eventroutes/2579f7f0-3716-47ba-aafe-bfbd69798bd1?api-version=2020-05-31-preview",
"Headers" : {
"User-Agent" : "azsdk-java-azure-digitaltwins-core/1.0.0-beta.3 (11.0.8; Windows 10; 10.0)",
"x-ms-client-request-id" : "6597899a-60f7-440e-a538-896f1dd7ddd6",
"Content-Type" : "application/json"
},
"Response" : {
"Strict-Transport-Security" : "max-age=2592000",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "204",
"Date" : "Thu, 01 Oct 2020 21:29:29 GMT"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.api.wus2.digitaltwins.azure.net/eventroutes/1a106057-b192-494c-a993-b888812ed3b7?api-version=2020-05-31-preview",
"Headers" : {
"User-Agent" : "azsdk-java-azure-digitaltwins-core/1.0.0-beta.3 (11.0.8; Windows 10; 10.0)",
"x-ms-client-request-id" : "5a36401c-6801-4297-9ea7-518f1cc89870",
"Content-Type" : "application/json"
},
"Response" : {
"Strict-Transport-Security" : "max-age=2592000",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "204",
"Date" : "Thu, 01 Oct 2020 21:29:28 GMT"
},
"Exception" : null
}, {
"Method" : "GET",
"Uri" : "https://REDACTED.api.wus2.digitaltwins.azure.net/eventroutes?api-version=2020-05-31-preview",
"Headers" : {
"User-Agent" : "azsdk-java-azure-digitaltwins-core/1.0.0-beta.3 (11.0.8; Windows 10; 10.0)",
"x-ms-client-request-id" : "0feeec4b-ef03-4363-9845-4beaeb9e4f19"
},
"Response" : {
"Strict-Transport-Security" : "max-age=2592000",
"retry-after" : "0",
"Content-Length" : "640",
"StatusCode" : "200",
"Body" : "{\"value\":[{\"id\":\"860ec2a5-ade0-4d0c-9545-0bb533b91eb0\",\"endpointName\":\"someEventHubEndpoint\",\"filter\":\"$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'\"},{\"id\":\"0ca3d236-73fb-4de1-964a-361bc37d8682\",\"endpointName\":\"someEventHubEndpoint\",\"filter\":\"$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'\"}],\"nextLink\":\"/EventRoutes?continuationToken=%5B%7B%22token%22%3A%22%2BRID%3A~9cpWAPHTRta0uwEAAAAAAA%3D%3D%23RT%3A1%23TRC%3A2%23ISV%3A2%23IEO%3A65551%22,%22range%22%3A%7B%22min%22%3A%22%22,%22max%22%3A%22FF%22%7D%7D%5D&api-version=2020-05-31-preview\"}",
"Date" : "Thu, 01 Oct 2020 21:29:29 GMT",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
}, {
"Method" : "GET",
"Uri" : "https://REDACTED.api.wus2.digitaltwins.azure.net/EventRoutes?continuationToken=%5B%7B%22token%22%3A%22%2BRID%3A~9cpWAPHTRta0uwEAAAAAAA%3D%3D%23RT%3A1%23TRC%3A2%23ISV%3A2%23IEO%3A65551%22,%22range%22%3A%7B%22min%22%3A%22%22,%22max%22%3A%22FF%22%7D%7D%5D&api-version=2020-05-31-preview",
"Headers" : {
"User-Agent" : "azsdk-java-azure-digitaltwins-core/1.0.0-beta.3 (11.0.8; Windows 10; 10.0)",
"x-ms-client-request-id" : "c6e67624-0be6-4ad9-8438-19f679194140"
},
"Response" : {
"Strict-Transport-Security" : "max-age=2592000",
"retry-after" : "0",
"Content-Length" : "640",
"StatusCode" : "200",
"Body" : "{\"value\":[{\"id\":\"245740f0-9508-4fb6-90a3-2dc1acadcc4f\",\"endpointName\":\"someEventHubEndpoint\",\"filter\":\"$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'\"},{\"id\":\"2579f7f0-3716-47ba-aafe-bfbd69798bd1\",\"endpointName\":\"someEventHubEndpoint\",\"filter\":\"$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'\"}],\"nextLink\":\"/EventRoutes?continuationToken=%5B%7B%22token%22%3A%22%2BRID%3A~9cpWAPHTRta2uwEAAAAAAA%3D%3D%23RT%3A2%23TRC%3A4%23ISV%3A2%23IEO%3A65551%22,%22range%22%3A%7B%22min%22%3A%22%22,%22max%22%3A%22FF%22%7D%7D%5D&api-version=2020-05-31-preview\"}",
"Date" : "Thu, 01 Oct 2020 21:29:29 GMT",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
}, {
"Method" : "GET",
"Uri" : "https://REDACTED.api.wus2.digitaltwins.azure.net/EventRoutes?continuationToken=%5B%7B%22token%22%3A%22%2BRID%3A~9cpWAPHTRta2uwEAAAAAAA%3D%3D%23RT%3A2%23TRC%3A4%23ISV%3A2%23IEO%3A65551%22,%22range%22%3A%7B%22min%22%3A%22%22,%22max%22%3A%22FF%22%7D%7D%5D&api-version=2020-05-31-preview",
"Headers" : {
"User-Agent" : "azsdk-java-azure-digitaltwins-core/1.0.0-beta.3 (11.0.8; Windows 10; 10.0)",
"x-ms-client-request-id" : "e7e55d2e-2d85-41c3-9147-4f4676f7c5db"
},
"Response" : {
"Strict-Transport-Security" : "max-age=2592000",
"retry-after" : "0",
"Content-Length" : "217",
"StatusCode" : "200",
"Body" : "{\"value\":[{\"id\":\"1a106057-b192-494c-a993-b888812ed3b7\",\"endpointName\":\"someEventHubEndpoint\",\"filter\":\"$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'\"}],\"nextLink\":null}",
"Date" : "Thu, 01 Oct 2020 21:29:29 GMT",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
} ],
"variables" : [ "860ec2a5-ade0-4d0c-9545-0bb533b91eb0", "0ca3d236-73fb-4de1-964a-361bc37d8682", "245740f0-9508-4fb6-90a3-2dc1acadcc4f", "2579f7f0-3716-47ba-aafe-bfbd69798bd1", "1a106057-b192-494c-a993-b888812ed3b7" ]
}