Search in sources :

Example 1 with CreateTriggerRequest

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

the class FunctionComputeClientTest method testCreateTriggerValidate.

@Test
public void testCreateTriggerValidate() {
    try {
        CreateTriggerRequest request = new CreateTriggerRequest(SERVICE_NAME, null);
        client.createTrigger(request);
        fail("ClientException is expected");
    } catch (ClientException e) {
        assertTrue(e.getMessage().contains(VALIDATE_MSG));
    }
    try {
        CreateTriggerRequest request = new CreateTriggerRequest(SERVICE_NAME, "");
        client.createTrigger(request);
        fail("ClientException is expected");
    } catch (ClientException e) {
        assertTrue(e.getMessage().contains(VALIDATE_MSG));
    }
    try {
        CreateTriggerRequest request = new CreateTriggerRequest(null, FUNCTION_NAME);
        client.createTrigger(request);
        fail("ClientException is expected");
    } catch (ClientException e) {
        assertTrue(e.getMessage().contains(VALIDATE_MSG));
    }
    try {
        CreateTriggerRequest request = new CreateTriggerRequest("", FUNCTION_NAME);
        client.createTrigger(request);
        fail("ClientException is expected");
    } catch (ClientException e) {
        assertTrue(e.getMessage().contains(VALIDATE_MSG));
    }
}
Also used : CreateTriggerRequest(com.aliyuncs.fc.request.CreateTriggerRequest) ClientException(com.aliyuncs.fc.exceptions.ClientException) Test(org.junit.Test)

Example 2 with CreateTriggerRequest

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

CreateTriggerRequest (com.aliyuncs.fc.request.CreateTriggerRequest)2 ClientException (com.aliyuncs.fc.exceptions.ClientException)1 OSSTriggerConfig (com.aliyuncs.fc.model.OSSTriggerConfig)1 CreateTriggerResponse (com.aliyuncs.fc.response.CreateTriggerResponse)1 Test (org.junit.Test)1