use of org.teiid.common.buffer.BufferManager in project teiid by teiid.
the class TestConnectorWorkItem method testTypeConversionClob.
@Test
public void testTypeConversionClob() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
String str = "hello world";
Clob clob = (Clob) ConnectorWorkItem.convertToRuntimeType(bm, new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(str.getBytes(Streamable.CHARSET));
}
}, DataTypeManager.DefaultDataClasses.CLOB, null);
assertEquals(str, clob.getSubString(1, str.length()));
}
use of org.teiid.common.buffer.BufferManager in project teiid by teiid.
the class TestConnectorWorkItem method testTypeConversion.
@Test
public void testTypeConversion() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
String str = "hello world";
Object source = new StreamSource(new StringReader(str));
XMLType xml = (XMLType) ConnectorWorkItem.convertToRuntimeType(bm, source, DataTypeManager.DefaultDataClasses.XML, null);
assertEquals(str, xml.getString());
source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader("<a/>")));
xml = (XMLType) ConnectorWorkItem.convertToRuntimeType(bm, source, DataTypeManager.DefaultDataClasses.XML, null);
XMLInputFactory in = XMLType.getXmlInputFactory();
XMLStreamReader reader = in.createXMLStreamReader(new StringReader(xml.getString()));
assertEquals(XMLEvent.START_DOCUMENT, reader.getEventType());
assertEquals(XMLEvent.START_ELEMENT, reader.next());
assertEquals("a", reader.getLocalName());
assertEquals(XMLEvent.END_ELEMENT, reader.next());
byte[] bytes = str.getBytes(Streamable.ENCODING);
source = new InputStreamFactory.BlobInputStreamFactory(BlobType.createBlob(bytes));
BlobType blob = (BlobType) ConnectorWorkItem.convertToRuntimeType(bm, source, DataTypeManager.DefaultDataClasses.BLOB, null);
assertArrayEquals(bytes, ObjectConverterUtil.convertToByteArray(blob.getBinaryStream()));
}
use of org.teiid.common.buffer.BufferManager in project teiid by teiid.
the class TestConnectorWorkItem method testConversionError.
@Test
public void testConversionError() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
List<String> list1 = new ArrayList<String>();
list1.add("1");
List<String> list2 = new ArrayList<String>();
list2.add("a");
final Iterator<List<String>> iter = Arrays.asList(list1, list2).iterator();
return new ResultSetExecution() {
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (iter.hasNext()) {
return iter.next();
}
return null;
}
};
}
};
ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector") {
public ExecutionFactory getExecutionFactory() {
return ef;
}
public Object getConnectionFactory() {
return null;
}
};
cm.start();
ef.setCopyLobs(true);
AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
// $NON-NLS-1$
requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT));
requestMsg.setBufferManager(bm);
ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
AtomicResultsMessage message = cwi.more();
List[] results = message.getResults();
assertEquals(1, results.length);
List<?> tuple = results[0];
assertEquals(1, tuple.get(0));
assertEquals(-1, message.getFinalRow());
try {
cwi.more();
fail();
} catch (TranslatorException e) {
// should throw the conversion error
}
}
use of org.teiid.common.buffer.BufferManager in project teiid by teiid.
the class TestConnectorWorkItem method testUnmodifibleList.
@Test
public void testUnmodifibleList() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
List<String> list1 = Collections.singletonList("1");
final Iterator<List<String>> iter = Arrays.asList(list1).iterator();
return new ResultSetExecution() {
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (iter.hasNext()) {
return iter.next();
}
return null;
}
};
}
};
ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector") {
public ExecutionFactory getExecutionFactory() {
return ef;
}
public Object getConnectionFactory() {
return null;
}
};
cm.start();
AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
// $NON-NLS-1$
requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT));
requestMsg.setBufferManager(bm);
ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
AtomicResultsMessage message = cwi.more();
List[] results = message.getResults();
assertEquals(1, results.length);
List<?> tuple = results[0];
assertEquals(1, tuple.get(0));
assertEquals(1, message.getFinalRow());
}
use of org.teiid.common.buffer.BufferManager in project teiid by teiid.
the class TestBufferManagerImpl method testProcessorBatchSize.
@Test
public void testProcessorBatchSize() {
BufferManager bm = BufferManagerFactory.createBufferManager();
int processorBatchSize = bm.getProcessorBatchSize();
List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
ElementSymbol a = new ElementSymbol("a");
a.setType(DataTypeManager.DefaultDataClasses.INTEGER);
// we use a somewhat high estimate of string size
ElementSymbol b = new ElementSymbol("b");
b.setType(DataTypeManager.DefaultDataClasses.STRING);
elements.add(a);
// fixed/small
assertEquals(processorBatchSize * 8, bm.getProcessorBatchSize(elements));
elements.add(b);
// small
assertEquals(processorBatchSize * 4, bm.getProcessorBatchSize(elements));
elements.add(b);
// moderately small
assertEquals(processorBatchSize * 2, bm.getProcessorBatchSize(elements));
elements.add(b);
elements.add(b);
// "normal"
assertEquals(processorBatchSize, bm.getProcessorBatchSize(elements));
elements.addAll(Collections.nCopies(28, b));
// large
assertEquals(processorBatchSize / 2, bm.getProcessorBatchSize(elements));
elements.addAll(Collections.nCopies(100, b));
// huge
assertEquals(processorBatchSize / 4, bm.getProcessorBatchSize(elements));
elements.addAll(Collections.nCopies(375, b));
// extreme
assertEquals(processorBatchSize / 8, bm.getProcessorBatchSize(elements));
}
Aggregations