Skip to content

Commit

Permalink
Merge pull request #204 from sadam21/update_dml_poll_error
Browse files Browse the repository at this point in the history
fix update model task polling

close #205
  • Loading branch information
martiner committed Jul 29, 2015
2 parents 9d2437f + 3bba003 commit ce59792
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/main/java/com/gooddata/dataset/DatasetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,11 @@ public void handlePollResult(final TaskState pollResult) {

@Override
public boolean isFinished(final ClientHttpResponse response) throws IOException {
if (!super.isFinished(response)) {
return false;
}
final TaskState taskState = extractData(response, TaskState.class);
if (taskState.isSuccess()) {
return true;
} else if (!taskState.isFinished()) {
return false;
}
throw new GoodDataException(errorMessage + ": " + taskState.getMessage());
}
Expand Down
23 changes: 20 additions & 3 deletions src/test/java/com/gooddata/dataset/DatasetServiceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import com.gooddata.GoodDataException;
import com.gooddata.gdc.TaskStatus;
import com.gooddata.project.Project;
import com.gooddata.util.ResourceUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;

import static com.gooddata.util.ResourceUtils.readFromResource;
Expand Down Expand Up @@ -227,7 +226,7 @@ public void shouldUpdateProjectData() throws IOException {
.havingMethodEqualTo("GET")
.havingPathEqualTo(STATUS_URI)
.respond()
.withStatus(202)
.withStatus(200) // REST API returns HTTP 200 when task is in RUNNING state :(
.withBody(MAPPER.writeValueAsString(new TaskState("RUNNING", STATUS_URI)))
.thenRespond()
.withStatus(200)
Expand All @@ -237,6 +236,24 @@ public void shouldUpdateProjectData() throws IOException {
gd.getDatasetService().updateProjectData(project, DML_MAQL).get();
}

@Test(expectedExceptions = GoodDataException.class)
public void shouldFailUpdateProjectDataServerError() throws IOException {
onRequest()
.havingMethodEqualTo("POST")
.havingPathEqualTo("/gdc/md/PROJECT_ID/dml/manage")
.respond()
.withStatus(202)
.withBody("{\"uri\" : \"" + STATUS_URI + "\"}");
onRequest()
.havingMethodEqualTo("GET")
.havingPathEqualTo(STATUS_URI)
.respond()
.withStatus(500)
;

gd.getDatasetService().updateProjectData(project, DML_MAQL).get();
}

@Test(expectedExceptions = GoodDataException.class)
public void shouldFailUpdateProjectData() throws IOException {
onRequest()
Expand Down

0 comments on commit ce59792

Please sign in to comment.