Search in sources :

Example 1 with CreateServiceRequest

use of com.aliyuncs.fc.request.CreateServiceRequest in project fc-java-sdk by aliyun.

the class FunctionComputeClientTest method testCreateServiceValidate.

@Test
public void testCreateServiceValidate() {
    try {
        CreateServiceRequest request = new CreateServiceRequest();
        client.createService(request);
        fail("ClientException is expected");
    } catch (ClientException e) {
        assertEquals(ErrorCodes.INVALID_ARGUMENT, e.getErrorCode());
    }
    try {
        CreateServiceRequest request = new CreateServiceRequest();
        client.createService(request);
        fail("ClientException is expected");
    } catch (ClientException e) {
        assertEquals(ErrorCodes.INVALID_ARGUMENT, e.getErrorCode());
    }
}
Also used : CreateServiceRequest(com.aliyuncs.fc.request.CreateServiceRequest) ClientException(com.aliyuncs.fc.exceptions.ClientException) Test(org.junit.Test)

Example 2 with CreateServiceRequest

use of com.aliyuncs.fc.request.CreateServiceRequest in project fc-java-sdk by aliyun.

the class FunctionComputeClientTest method createService.

private CreateServiceResponse createService(String serviceName) {
    CreateServiceRequest createSReq = new CreateServiceRequest();
    createSReq.setServiceName(serviceName);
    createSReq.setDescription(SERVICE_DESC_OLD);
    createSReq.setRole(ROLE);
    return client.createService(createSReq);
}
Also used : CreateServiceRequest(com.aliyuncs.fc.request.CreateServiceRequest)

Example 3 with CreateServiceRequest

use of com.aliyuncs.fc.request.CreateServiceRequest 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

CreateServiceRequest (com.aliyuncs.fc.request.CreateServiceRequest)3 ClientException (com.aliyuncs.fc.exceptions.ClientException)2 Test (org.junit.Test)2 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