Search in sources :

Example 1 with CreateTriggerResponse

use of com.aliyuncs.fc.response.CreateTriggerResponse in project fc-java-sdk by aliyun.

the class FunctionComputeClientTest method ignoreTestListTriggers.

public void ignoreTestListTriggers() {
    final int numTriggers = 5;
    final int limit = 2;
    // Create service
    createService(SERVICE_NAME);
    createFunction(FUNCTION_NAME);
    // Create multiple trigger under the test function
    for (int i = 0; i < numTriggers; i++) {
        String prefix = "prefix";
        String suffix = "suffix";
        CreateTriggerResponse createTResp = createTrigger(TRIGGER_NAME + i, prefix + i, suffix + i);
        assertFalse(Strings.isNullOrEmpty(createTResp.getRequestId()));
    }
    ListTriggersRequest listTReq = new ListTriggersRequest(SERVICE_NAME, FUNCTION_NAME);
    listTReq.setLimit(limit);
    ListTriggersResponse listTResp = client.listTriggers(listTReq);
    int numCalled = 1;
    String nextToken = listTResp.getNextToken();
    while (nextToken != null) {
        listTReq.setNextToken(nextToken);
        listTResp = client.listTriggers(listTReq);
        nextToken = listTResp.getNextToken();
        numCalled++;
    }
    assertEquals(numTriggers / limit + 1, numCalled);
    for (int i = 0; i < numTriggers; i++) {
        DeleteTriggerResponse deleteTResp = deleteTrigger(SERVICE_NAME, FUNCTION_NAME, TRIGGER_NAME + i);
        assertFalse(Strings.isNullOrEmpty(deleteTResp.getRequestId()));
    }
}
Also used : ListTriggersResponse(com.aliyuncs.fc.response.ListTriggersResponse) ListTriggersRequest(com.aliyuncs.fc.request.ListTriggersRequest) CreateTriggerResponse(com.aliyuncs.fc.response.CreateTriggerResponse) DeleteTriggerResponse(com.aliyuncs.fc.response.DeleteTriggerResponse)

Example 2 with CreateTriggerResponse

use of com.aliyuncs.fc.response.CreateTriggerResponse in project fc-java-sdk by aliyun.

the class FunctionComputeClientTest method createTrigger.

private CreateTriggerResponse createTrigger(String triggerName, String prefix, String suffix) {
    CreateTriggerRequest createTReq = new CreateTriggerRequest(SERVICE_NAME, FUNCTION_NAME);
    createTReq.setTriggerName(triggerName);
    createTReq.setTriggerType(TRIGGER_TYPE_OSS);
    createTReq.setInvocationRole(INVOCATION_ROLE);
    createTReq.setSourceArn(OSS_SOURCE_ARN);
    createTReq.setTriggerConfig(new OSSTriggerConfig(new String[] { "oss:ObjectCreated:*" }, prefix, suffix));
    CreateTriggerResponse resp = client.createTrigger(createTReq);
    try {
        // Add some sleep since OSS notifications create is not strongly consistent
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    return resp;
}
Also used : OSSTriggerConfig(com.aliyuncs.fc.model.OSSTriggerConfig) CreateTriggerRequest(com.aliyuncs.fc.request.CreateTriggerRequest) CreateTriggerResponse(com.aliyuncs.fc.response.CreateTriggerResponse)

Aggregations

CreateTriggerResponse (com.aliyuncs.fc.response.CreateTriggerResponse)2 OSSTriggerConfig (com.aliyuncs.fc.model.OSSTriggerConfig)1 CreateTriggerRequest (com.aliyuncs.fc.request.CreateTriggerRequest)1 ListTriggersRequest (com.aliyuncs.fc.request.ListTriggersRequest)1 DeleteTriggerResponse (com.aliyuncs.fc.response.DeleteTriggerResponse)1 ListTriggersResponse (com.aliyuncs.fc.response.ListTriggersResponse)1