use of com.treasuredata.client.model.TDJobRequestBuilder 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));
}
use of com.treasuredata.client.model.TDJobRequestBuilder 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));
}
use of com.treasuredata.client.model.TDJobRequestBuilder 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));
}
use of com.treasuredata.client.model.TDJobRequestBuilder 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));
}
Aggregations