use of com.aliyuncs.fc.request.ListServicesRequest in project fc-java-sdk by aliyun.
the class FunctionComputeClientTest method testListServices.
@Test
public void testListServices() {
final int numServices = 10;
final int limit = 3;
// Create multiple services
for (int i = 0; i < numServices; i++) {
try {
client.getService(new GetServiceRequest(SERVICE_NAME + i));
cleanupService(SERVICE_NAME + i);
} catch (ClientException e) {
if (!ErrorCodes.SERVICE_NOT_FOUND.equals(e.getErrorCode())) {
throw new RuntimeException("Cleanup failed");
}
}
CreateServiceRequest request = new CreateServiceRequest();
request.setServiceName(SERVICE_NAME + i);
request.setDescription(SERVICE_DESC_OLD);
request.setRole(ROLE);
CreateServiceResponse response = client.createService(request);
assertFalse(Strings.isNullOrEmpty(response.getRequestId()));
}
ListServicesRequest listRequest = new ListServicesRequest();
listRequest.setLimit(limit);
listRequest.setPrefix(SERVICE_NAME);
ListServicesResponse listResponse = client.listServices(listRequest);
int numCalled = 1;
String nextToken = listResponse.getNextToken();
while (nextToken != null) {
listRequest.setNextToken(nextToken);
listResponse = client.listServices(listRequest);
nextToken = listResponse.getNextToken();
numCalled++;
}
assertEquals(numServices / limit + 1, numCalled);
// Delete services
for (int i = 0; i < numServices; i++) {
cleanupService(SERVICE_NAME + i);
}
}
Aggregations