use of org.teiid.client.lob.LobChunk in project teiid by teiid.
the class TestLobChunkInputStream method testReadByteArray.
public void testReadByteArray() throws Exception {
LobChunkProducer chunkProducer = new LobChunkProducer() {
// $NON-NLS-1$ //$NON-NLS-2$
Iterator<LobChunk> chuncks = Arrays.asList(new LobChunk("hello ".getBytes(), false), new LobChunk("world".getBytes(), true)).iterator();
@Override
public LobChunk getNextChunk() throws IOException {
return chuncks.next();
}
@Override
public void close() throws IOException {
}
};
LobChunkInputStream stream = new LobChunkInputStream(chunkProducer);
// $NON-NLS-1$
assertEquals("hello world", ObjectConverterUtil.convertToString(stream));
}
use of org.teiid.client.lob.LobChunk in project teiid by teiid.
the class LobWorkItem method run.
public void run() {
LobChunk chunk = null;
Exception ex = null;
boolean shouldClose = false;
try {
// save for future
if (stream == null) {
stream = createLobStream(streamId);
}
// now get the chunk from stream
chunk = stream.getNextChunk();
parent.dataBytes.addAndGet(chunk.getBytes().length);
shouldClose = chunk.isLast();
} catch (TeiidComponentException e) {
LogManager.logWarning(org.teiid.logging.LogConstants.CTX_DQP, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30027));
ex = e;
} catch (IOException | SQLException e) {
// treat this as a processing exception
ex = new TeiidProcessingException(e);
}
synchronized (this) {
if (ex != null) {
resultsReceiver.exceptionOccurred(ex);
shouldClose = true;
} else {
resultsReceiver.receiveResults(chunk);
}
resultsReceiver = null;
}
if (shouldClose) {
close();
}
}
use of org.teiid.client.lob.LobChunk in project teiid by teiid.
the class TestResultSet method testXML.
@Test
public void testXML() throws Exception {
StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY);
ResultsFuture<LobChunk> future = new ResultsFuture<LobChunk>();
future.getResultsReceiver().receiveResults(new LobChunk("<a/>".getBytes(Charset.forName("UTF-8")), true));
XMLType result = new XMLType();
Mockito.stub(statement.getDQP().requestNextLobChunk(0, 0, result.getReferenceStreamId())).toReturn(future);
ResultsMessage resultsMsg = new ResultsMessage();
result.setEncoding("UTF-8");
resultsMsg.setResults(new List<?>[] { Arrays.asList(result) });
resultsMsg.setLastRow(1);
resultsMsg.setFirstRow(1);
resultsMsg.setFinalRow(1);
// $NON-NLS-1$
resultsMsg.setColumnNames(new String[] { "x" });
// $NON-NLS-1$
resultsMsg.setDataTypes(new String[] { "xml" });
ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement);
cs.next();
assertEquals("<a/>", cs.getString(1));
}
use of org.teiid.client.lob.LobChunk in project teiid by teiid.
the class TestByteLobChunk method testSerialization.
public void testSerialization() throws Exception {
// $NON-NLS-1$
String testString = "This is test string for testing ByteLobChunk";
LobChunk chunk = new LobChunk(testString.getBytes(), true);
LobChunk result = UnitTestUtil.helpSerialize(chunk);
assertTrue(Arrays.equals(chunk.getBytes(), result.getBytes()));
assertTrue(result.isLast());
}
use of org.teiid.client.lob.LobChunk in project teiid by teiid.
the class TestByteLobChunk method testGetBytes.
public void testGetBytes() {
// $NON-NLS-1$
String testString = "This is test string for testing ByteLobChunk";
LobChunk chunk = new LobChunk(testString.getBytes(), false);
assertEquals(testString, new String(chunk.getBytes()));
assertFalse(chunk.isLast());
}
Aggregations