Search in sources :

Example 1 with TDSavedQueryStartRequest

use of com.treasuredata.client.model.TDSavedQueryStartRequest in project td-client-java by treasure-data.

the class TestTDClient method startSavedQueryWithDomainKey.

@Test
public void startSavedQueryWithDomainKey() throws Exception {
    String domainKey = randomDomainKey();
    String queryName = newTemporaryName("td_client_test");
    TDSaveQueryRequest query = TDSavedQuery.newBuilder(queryName, TDJob.Type.PRESTO, SAMPLE_DB, "select 1", "Asia/Tokyo").setCron("0 * * * *").setPriority(-1).setRetryLimit(2).setResult("mysql://testuser:pass@somemysql.address/somedb/sometable").build();
    try {
        client.saveQuery(query);
        int epoch1 = 1457046001;
        int epoch2 = epoch1 + 1;
        // Claim the domain key
        TDSavedQueryStartRequest request1 = TDSavedQueryStartRequest.builder().name(queryName).scheduledTime(new Date(epoch1 * 1000L)).domainKey(domainKey).build();
        String jobId = client.startSavedQuery(request1);
        // Attempt to use the same domain key again and verify that we get a conflict
        TDSavedQueryStartRequest request2 = TDSavedQueryStartRequest.builder().name(queryName).scheduledTime(new Date(epoch2 * 1000L)).domainKey(domainKey).build();
        try {
            client.startSavedQuery(request2);
            fail("Expected " + TDClientHttpConflictException.class.getName());
        } catch (TDClientHttpConflictException e) {
            assertThat(e.getConflictsWith(), is(Optional.of(jobId)));
        }
    } finally {
        client.deleteSavedQuery(queryName);
    }
}
Also used : Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) Date(java.util.Date) TDSaveQueryRequest(com.treasuredata.client.model.TDSaveQueryRequest) TDSavedQueryStartRequest(com.treasuredata.client.model.TDSavedQueryStartRequest) Test(org.junit.Test)

Aggregations

TDSaveQueryRequest (com.treasuredata.client.model.TDSaveQueryRequest)1 TDSavedQueryStartRequest (com.treasuredata.client.model.TDSavedQueryStartRequest)1 Date (java.util.Date)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)1 Test (org.junit.Test)1