@Ignore @Test(expected = TranslatorException.class) public void testIsImmutablePropertyFails() throws Exception { /* * Setup: * 1. requestMsg.isTransactional() must be TRUE * 2. manager.isXa() must be FALSE () * 3. command must NOT be a SELECT * 4. Then, set isImmutable to FALSE, and we should FAIL */ ConnectorManager cm = TestConnectorManager.getConnectorManager(); ((FakeConnector) cm.getExecutionFactory()).setImmutable(false); // command must not be a SELECT Command command = helpGetCommand( "update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT); // $NON-NLS-1$ AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1); requestMsg.setCommand(command); // To make the AtomicRequestMessage transactional, construct your own requestMsg.setTransactionContext( new TransactionContext() { @Override public Xid getXid() { return Mockito.mock(Xid.class); } }); new ConnectorWorkItem(requestMsg, cm); }
@Test public void testSourcHints() throws Exception { Command command = helpGetCommand( "update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT); // $NON-NLS-1$ command.setSourceHint(new SourceHint()); AtomicRequestMessage arm = createNewAtomicRequestMessage(1, 1); arm.setCommand(command); ConnectorManager cm = TestConnectorManager.getConnectorManager(); cm.registerRequest(arm); }
@Test public void testSourceNotRequired() throws Exception { Command command = helpGetCommand( "update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT); // $NON-NLS-1$ AtomicRequestMessage arm = createNewAtomicRequestMessage(1, 1); arm.setCommand(command); ConnectorManager cm = TestConnectorManager.getConnectorManager(); cm.getExecutionFactory().setSourceRequired(false); ConnectorWork synchConnectorWorkItem = cm.registerRequest(arm); synchConnectorWorkItem.execute(); synchConnectorWorkItem.close(); FakeConnector fc = (FakeConnector) cm.getExecutionFactory(); assertEquals(1, fc.getConnectionCount()); assertEquals(1, fc.getCloseCount()); }
private AtomicResultsMessage helpExecuteUpdate(boolean batch, boolean single) throws Exception, Throwable { Command command = helpGetCommand( "update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT); // $NON-NLS-1$ if (batch) { command = new BatchedUpdateCommand(Arrays.asList(command, command)); } AtomicRequestMessage arm = createNewAtomicRequestMessage(1, 1); arm.setCommand(command); ConnectorManager connectorManager = TestConnectorManager.getConnectorManager(); ((FakeConnector) connectorManager.getExecutionFactory()).setReturnSingleUpdate(single); ConnectorWorkItem synchConnectorWorkItem = new ConnectorWorkItem(arm, connectorManager); synchConnectorWorkItem.execute(); return synchConnectorWorkItem.more(); }
@Test public void testConvertIn() throws Exception { Command command = helpGetCommand( "select intkey from bqt1.smalla where stringkey in ('1', '2')", EXAMPLE_BQT); //$NON-NLS-1$ AtomicRequestMessage arm = createNewAtomicRequestMessage(1, 1); arm.setCommand(command); ConnectorManager cm = TestConnectorManager.getConnectorManager(); cm.getExecutionFactory().setSourceRequired(false); ConnectorWork synchConnectorWorkItem = cm.registerRequest(arm); synchConnectorWorkItem.execute(); synchConnectorWorkItem.close(); FakeConnector fc = (FakeConnector) cm.getExecutionFactory(); assertEquals( "SELECT SmallA.IntKey FROM SmallA WHERE SmallA.StringKey = '2' OR SmallA.StringKey = '1'", fc.getCommands().get(0).toString()); assertEquals(1, fc.getConnectionCount()); assertEquals(1, fc.getCloseCount()); }
@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 ConnectorManager("FakeConnector", "FakeConnector") { // $NON-NLS-1$ //$NON-NLS-2$ public ExecutionFactory getExecutionFactory() { return ef; } public Object getConnectionFactory() { return null; } }; cm.start(); AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1); requestMsg.setCommand( helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT)); // $NON-NLS-1$ 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()); }
@Test public void testLobs() 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 { return new ResultSetExecution() { private boolean returned; @Override public void execute() throws TranslatorException {} @Override public void close() {} @Override public void cancel() throws TranslatorException {} @Override public List<?> next() throws TranslatorException, DataNotAvailableException { if (returned) { return null; } returned = true; return Arrays.asList(AutoGenDataService.CLOB_VAL); } }; } }; ConnectorManager cm = new ConnectorManager("FakeConnector", "FakeConnector") { // $NON-NLS-1$ //$NON-NLS-2$ public ExecutionFactory getExecutionFactory() { return ef; } public Object getConnectionFactory() { return null; } }; cm.start(); ef.setCopyLobs(true); AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1); requestMsg.setCommand( helpGetCommand("SELECT CLOB_COLUMN FROM LOB_TESTING_ONE", EXAMPLE_BQT)); // $NON-NLS-1$ requestMsg.setBufferManager(bm); ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute(); AtomicResultsMessage message = cwi.more(); List[] resutls = message.getResults(); List<?> tuple = resutls[0]; ClobType clob = (ClobType) tuple.get(0); assertEquals(StorageMode.MEMORY, InputStreamFactory.getStorageMode(clob)); assertTrue(message.supportsImplicitClose()); ef.setCopyLobs(false); cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute(); message = cwi.more(); resutls = message.getResults(); tuple = resutls[0]; clob = (ClobType) tuple.get(0); assertEquals(StorageMode.OTHER, InputStreamFactory.getStorageMode(clob)); assertFalse(message.supportsImplicitClose()); }