Search in sources :

Example 1 with TDJobRequest

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

the class TestTDClient method submitJobWithResultConnectionSettings.

@Test
public void submitJobWithResultConnectionSettings() throws Exception {
    client = mockClient();
    String connectionSettings = "{\"type\":\"null\"}";
    server.enqueue(new MockResponse().setBody("{\"job_id\":\"17\"}"));
    TDJobRequest request = new TDJobRequestBuilder().setType(TDJob.Type.PRESTO).setDatabase("sample_datasets").setQuery("select 1").setResultConnectionSettings(connectionSettings).createTDJobRequest();
    String jobId = client.submit(request);
    assertThat(jobId, is("17"));
    RecordedRequest recordedRequest = server.takeRequest();
    String body = URLDecoder.decode(recordedRequest.getBody().readUtf8(), "UTF-8");
    assertThat(body, containsString("result_connection_settings=" + connectionSettings));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) TDJobRequestBuilder(com.treasuredata.client.model.TDJobRequestBuilder) TDJobRequest(com.treasuredata.client.model.TDJobRequest) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 2 with TDJobRequest

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

the class TestTDClient method submitJobWithScheduledTime.

@Test
public void submitJobWithScheduledTime() throws Exception {
    long scheduledTime = 1368080054;
    TDJobRequest request = new TDJobRequestBuilder().setType(TDJob.Type.PRESTO).setDatabase("sample_datasets").setQuery("select TD_SCHEDULED_TIME()").setScheduledTime(scheduledTime).createTDJobRequest();
    String jobId = client.submit(request);
    waitJobCompletion(jobId);
    JSONArray array = client.jobResult(jobId, TDResultFormat.JSON, new Function<InputStream, JSONArray>() {

        @Override
        public JSONArray apply(InputStream input) {
            try {
                String result = new String(ByteStreams.toByteArray(input), StandardCharsets.UTF_8);
                logger.info("result:\n" + result);
                return new JSONArray(result);
            } catch (Exception e) {
                throw Throwables.propagate(e);
            }
        }
    });
    assertEquals(1, array.length());
    assertEquals(scheduledTime, array.getLong(0));
}
Also used : TDJobRequestBuilder(com.treasuredata.client.model.TDJobRequestBuilder) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) JSONArray(org.json.JSONArray) TDJobRequest(com.treasuredata.client.model.TDJobRequest) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) JSONException(org.json.JSONException) ExpectedException(org.junit.rules.ExpectedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with TDJobRequest

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

the class TestTDClient method submitJobWithResultConnectionId.

@Test
public void submitJobWithResultConnectionId() throws Exception {
    client = mockClient();
    long connectionId = 9321;
    server.enqueue(new MockResponse().setBody("{\"job_id\":\"17\"}"));
    TDJobRequest request = new TDJobRequestBuilder().setType(TDJob.Type.PRESTO).setDatabase("sample_datasets").setQuery("select 1").setResultConnectionId(connectionId).createTDJobRequest();
    String jobId = client.submit(request);
    assertThat(jobId, is("17"));
    RecordedRequest recordedRequest = server.takeRequest();
    String body = URLDecoder.decode(recordedRequest.getBody().readUtf8(), "UTF-8");
    assertThat(body, containsString("result_connection_id=" + connectionId));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) TDJobRequestBuilder(com.treasuredata.client.model.TDJobRequestBuilder) TDJobRequest(com.treasuredata.client.model.TDJobRequest) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 4 with TDJobRequest

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

the class TestTDClient method submitJobWithDomainKey.

@Test
public void submitJobWithDomainKey() throws Exception {
    String domainKey = randomDomainKey();
    TDJobRequest request1 = new TDJobRequestBuilder().setType(TDJob.Type.PRESTO).setDatabase("sample_datasets").setQuery("select 1").setDomainKey(domainKey).createTDJobRequest();
    String jobId = client.submit(request1);
    waitJobCompletion(jobId);
    TDJobRequest request2 = new TDJobRequestBuilder().setType(TDJob.Type.PRESTO).setDatabase("sample_datasets").setQuery("select 1").setDomainKey(domainKey).createTDJobRequest();
    try {
        client.submit(request2);
        fail("Expected " + TDClientHttpConflictException.class.getName());
    } catch (TDClientHttpConflictException e) {
        assertThat(e.getConflictsWith(), is(Optional.of(jobId)));
    }
    TDJobSummary statusByDomainKey = client.jobStatusByDomainKey(domainKey);
    assertThat(statusByDomainKey.getJobId(), is(jobId));
}
Also used : TDJobRequestBuilder(com.treasuredata.client.model.TDJobRequestBuilder) TDJobRequest(com.treasuredata.client.model.TDJobRequest) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) TDJobSummary(com.treasuredata.client.model.TDJobSummary) Test(org.junit.Test)

Aggregations

TDJobRequest (com.treasuredata.client.model.TDJobRequest)4 TDJobRequestBuilder (com.treasuredata.client.model.TDJobRequestBuilder)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)4 Test (org.junit.Test)4 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 TDJobSummary (com.treasuredata.client.model.TDJobSummary)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 ExpectedException (org.junit.rules.ExpectedException)1