Skip to content

Fix periodic pull failure (2.x) #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.dockerjava.api.async.ResultCallback;

/**
Expand Down Expand Up @@ -41,8 +42,12 @@ public void processResponseStream(InputStream response, ResultCallback<T> result
JsonToken nextToken = jp.nextToken();
while (!closed && nextToken != null && nextToken != JsonToken.END_OBJECT) {
try {
T next = OBJECT_MAPPER.readValue(jp, clazz);
resultCallback.onNext(next);
ObjectNode objectNode = OBJECT_MAPPER.readTree(jp);
// exclude empty item serialization into class #461
if (!(objectNode.size() == 0)) {
T next = OBJECT_MAPPER.treeToValue(objectNode, clazz);
resultCallback.onNext(next);
}
} catch (Exception e) {
resultCallback.onError(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Created on 16.02.2016
*/
package com.github.dockerjava.core.async;

import static org.testng.Assert.assertFalse;

import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.testng.annotations.Test;

import com.github.dockerjava.api.async.ResultCallback;
import com.github.dockerjava.api.model.PullResponseItem;


/**
*
* @author Marcus Linke
*
*/
public class JsonStreamProcessorTest {

@Test
public void processEmptyJson() throws Exception {

InputStream response = new ByteArrayInputStream("{}".getBytes());

JsonStreamProcessor<PullResponseItem> jsonStreamProcessor = new JsonStreamProcessor<PullResponseItem>(PullResponseItem.class);

final List<Boolean> completed = new ArrayList<Boolean>();

jsonStreamProcessor.processResponseStream(response, new ResultCallback<PullResponseItem>() {

@Override
public void close() throws IOException {
}

@Override
public void onStart(Closeable closeable) {
}

@Override
public void onNext(PullResponseItem object) {
assertFalse(true, "onNext called for empty json");
}

@Override
public void onError(Throwable throwable) {
}

@Override
public void onComplete() {
completed.add(true);
}
});

assertFalse(completed.isEmpty(), "Stream processing not completed");
}

}