Search in sources :

Example 1 with ListServicesRequest

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);
    }
}
Also used : ListServicesRequest(com.aliyuncs.fc.request.ListServicesRequest) CreateServiceRequest(com.aliyuncs.fc.request.CreateServiceRequest) ListServicesResponse(com.aliyuncs.fc.response.ListServicesResponse) CreateServiceResponse(com.aliyuncs.fc.response.CreateServiceResponse) GetServiceRequest(com.aliyuncs.fc.request.GetServiceRequest) ClientException(com.aliyuncs.fc.exceptions.ClientException) Test(org.junit.Test)

Aggregations

ClientException (com.aliyuncs.fc.exceptions.ClientException)1 CreateServiceRequest (com.aliyuncs.fc.request.CreateServiceRequest)1 GetServiceRequest (com.aliyuncs.fc.request.GetServiceRequest)1 ListServicesRequest (com.aliyuncs.fc.request.ListServicesRequest)1 CreateServiceResponse (com.aliyuncs.fc.response.CreateServiceResponse)1 ListServicesResponse (com.aliyuncs.fc.response.ListServicesResponse)1 Test (org.junit.Test)1