use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class TestConnectorWorkItem method testIsImmutablePropertyFails.
@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
// $NON-NLS-1$
Command command = helpGetCommand("update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT);
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);
}
use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class TestTransactionServer method testRequestRollback.
@Test
public void testRequestRollback() throws Exception {
TransactionContext tc = server.getOrCreateTransactionContext(THREAD1);
server.begin(tc);
server.rollback(tc);
assertEquals(TransactionContext.Scope.NONE, tc.getTransactionType());
Mockito.verify(tm).rollback();
}
use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class TestTransactionServer method testGlobalOnePhaseCommit.
@Test
public void testGlobalOnePhaseCommit() throws Exception {
server.start(THREAD1, XID1, XAResource.TMNOFLAGS, 100, false);
TransactionContext tc = server.getOrCreateTransactionContext(THREAD1);
server.end(THREAD1, XID1, XAResource.TMSUCCESS, false);
server.prepare(THREAD1, XID1, false);
server.commit(THREAD1, XID1, true, false);
Mockito.verify(xaTerminator).commit(tc.getXid(), false);
}
use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class TestTransactionServer method testGlobalOnePhaseRoolback.
@Test
public void testGlobalOnePhaseRoolback() throws Exception {
server.start(THREAD1, XID1, XAResource.TMNOFLAGS, 100, false);
TransactionContext tc = server.getOrCreateTransactionContext(THREAD1);
server.end(THREAD1, XID1, XAResource.TMSUCCESS, false);
server.prepare(THREAD1, XID1, false);
server.rollback(THREAD1, XID1, false);
// since there are two sources the commit is not single phase
Mockito.verify(xaTerminator).rollback(tc.getXid());
}
use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class TestInsertProcessing method helpInsertIntoWithSubquery.
public void helpInsertIntoWithSubquery(Capability cap, boolean txn) throws Exception {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(cap, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
HardcodedDataManager dataManager = new HardcodedDataManager() {
@Override
public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
if (command instanceof Insert) {
Insert insert = (Insert) command;
if (insert.getTupleSource() != null) {
commandHistory.add(insert);
TupleSource ts = insert.getTupleSource();
int count = 0;
try {
while (ts.nextTuple() != null) {
count++;
}
return CollectionTupleSource.createUpdateCountArrayTupleSource(count);
} catch (TeiidProcessingException e) {
throw new RuntimeException(e);
}
}
}
return super.registerRequest(context, command, modelName, parameterObject);
}
};
List[] data = new List[txn ? 2 : 50];
for (int i = 1; i <= data.length; i++) {
data[i - 1] = Arrays.asList(String.valueOf(i), i, (i % 2 == 0) ? Boolean.TRUE : Boolean.FALSE, Double.valueOf(i));
}
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1", data);
if (cap != null) {
switch(cap) {
case BATCHED_UPDATES:
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"BatchedUpdate{I,I}", new List[] { Arrays.asList(1), Arrays.asList(1) });
break;
case INSERT_WITH_QUERYEXPRESSION:
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"INSERT INTO pm1.g2 (e1, e2, e3, e4) SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1", new List[] { Arrays.asList(new Object[] { 2 }) });
break;
}
} else {
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('1', 1, FALSE, 1.0)", new List[] { Arrays.asList(new Object[] { new Integer(1) }) });
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('2', 2, TRUE, 2.0)", new List[] { Arrays.asList(new Object[] { new Integer(1) }) });
}
// $NON-NLS-1$
String sql = "INSERT INTO pm1.g2 SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 from pm1.g1";
Command command = helpParse(sql);
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
List<?>[] expected = new List[] { Arrays.asList(txn ? 2 : 50) };
CommandContext cc = TestProcessor.createCommandContext();
if (!txn) {
TransactionContext tc = new TransactionContext();
cc.setTransactionContext(tc);
cc.setBufferManager(null);
cc.setProcessorBatchSize(2);
}
helpProcess(plan, cc, dataManager, expected);
// check the command hist to ensure it contains the expected commands
if (cap == Capability.BATCHED_UPDATES) {
BatchedUpdateCommand bu = (BatchedUpdateCommand) dataManager.getCommandHistory().get(1);
assertEquals(2, bu.getUpdateCommands().size());
// $NON-NLS-1$
assertEquals("INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('1', 1, FALSE, 1.0)", bu.getUpdateCommands().get(0).toString());
// $NON-NLS-1$
assertEquals("INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('2', 2, TRUE, 2.0)", bu.getUpdateCommands().get(1).toString());
} else if (cap == Capability.INSERT_WITH_ITERATOR) {
assertEquals(txn ? 6 : 9, dataManager.getCommandHistory().size());
}
}
Aggregations