use of org.teiid.client.util.ResultsFuture in project teiid by teiid.
the class MaterializationManager method runJob.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void runJob(final CompositeVDB vdb, final Table table, final long ttl, final boolean onetimeJob) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
String command = "execute SYSADMIN.loadMatView('" + StringUtil.replaceAll(table.getParent().getName(), "'", "''") + "','" + StringUtil.replaceAll(table.getName(), "'", "''") + "')";
try {
final AtomicInteger procReturn = new AtomicInteger();
executeAsynchQuery(vdb.getVDB(), command, new DQPCore.ResultsListener() {
@Override
public void onResults(List<String> columns, List<? extends List<?>> results) throws Exception {
procReturn.set((Integer) results.get(0).get(0));
}
}).addCompletionListener(new CompletionListener() {
@Override
public void onCompletion(ResultsFuture future) {
try {
future.get();
if (!onetimeJob) {
if (procReturn.get() >= 0) {
scheduleSnapshotJob(vdb, table, ttl, ttl, onetimeJob);
} else {
// when in error re-schedule in 1 min or less
scheduleSnapshotJob(vdb, table, ttl, Math.min(ttl / 4, WAITTIME), onetimeJob);
}
}
} catch (InterruptedException e) {
} catch (ExecutionException e) {
LogManager.logWarning(LogConstants.CTX_MATVIEWS, e, e.getMessage());
// re-schedule the same job in one minute
scheduleSnapshotJob(vdb, table, ttl, Math.min(ttl / 4, WAITTIME), onetimeJob);
}
}
});
} catch (SQLException e) {
LogManager.logWarning(LogConstants.CTX_MATVIEWS, e, e.getMessage());
// re-schedule the same job in one minute
scheduleSnapshotJob(vdb, table, ttl, Math.min(ttl / 4, WAITTIME), onetimeJob);
}
}
use of org.teiid.client.util.ResultsFuture in project teiid by teiid.
the class TestLocalConnections method testWaitForLoadTimeout.
@Test
public void testWaitForLoadTimeout() throws Exception {
final ResultsFuture<Void> future = new ResultsFuture<Void>();
Thread t = new Thread() {
@Override
public void run() {
try {
server.createConnection("jdbc:teiid:not_there.1;waitForLoad=1000");
future.getResultsReceiver().receiveResults(null);
} catch (Exception e) {
future.getResultsReceiver().exceptionOccurred(e);
}
}
};
t.setDaemon(true);
t.start();
assertFalse(future.isDone());
try {
server.deployVDB(new ByteArrayInputStream("<vdb name=\"not_there\" version=\"1\"><model name=\"myschema\"><source name=\"x\" translator-name=\"x\" connection-jndi-name=\"x\"/></model></vdb>".getBytes(Charset.forName("UTF-8"))));
fail();
} catch (TranslatorException e) {
// no connection factory
}
try {
future.get(5000, TimeUnit.SECONDS);
fail();
} catch (ExecutionException e) {
assertTrue(e.getMessage().contains("TEIID40097"));
} finally {
server.undeployVDB("not_there");
}
}
use of org.teiid.client.util.ResultsFuture in project teiid by teiid.
the class TestExecutionReuse method testReusableAsynchContinuous.
@Test
public void testReusableAsynchContinuous() throws Exception {
Connection c = server.createConnection("jdbc:teiid:partssupplier");
Statement s = c.createStatement();
TeiidStatement ts = s.unwrap(TeiidStatement.class);
final ResultsFuture<Integer> result = new ResultsFuture<Integer>();
ts.submitExecute("select part_id from parts order by part_id", new StatementCallback() {
int rowCount;
@Override
public void onRow(Statement stmt, ResultSet rs) throws SQLException {
rowCount++;
if (rowCount == EXEC_COUNT) {
stmt.close();
}
}
@Override
public void onException(Statement stmt, Exception e) {
result.getResultsReceiver().exceptionOccurred(e);
}
@Override
public void onComplete(Statement stmt) {
result.getResultsReceiver().receiveResults(rowCount);
}
}, new RequestOptions().continuous(true));
synchronized (TestExecutionReuse.class) {
while (!isDisposed) {
TestExecutionReuse.class.wait();
}
}
assertEquals(EXEC_COUNT, result.get().intValue());
assertTrue(ec.getCommandContext().isContinuous());
Mockito.verify(execution, Mockito.times(1)).dispose();
Mockito.verify(execution, Mockito.times(EXEC_COUNT)).execute();
Mockito.verify(execution, Mockito.times(EXEC_COUNT)).close();
Mockito.verify(execution, Mockito.times(EXEC_COUNT - 1)).reset((Command) Mockito.anyObject(), (ExecutionContext) Mockito.anyObject(), Mockito.anyObject());
}
use of org.teiid.client.util.ResultsFuture in project teiid by teiid.
the class TestAsynch method testAsynchContinuousMergeBlock.
@Test
public void testAsynchContinuousMergeBlock() throws Exception {
Statement stmt = this.internalConnection.createStatement();
stmt.execute("create temporary table t (c string, primary key (c))");
stmt.execute("set autoCommitTxn off");
TeiidStatement ts = stmt.unwrap(TeiidStatement.class);
final ResultsFuture<Integer> result = new ResultsFuture<Integer>();
ts.submitExecute("begin merge into t select name from schemas limit 2; select rowcount; end", new StatementCallback() {
int rowCount;
@Override
public void onRow(Statement s, ResultSet rs) throws SQLException {
rowCount++;
if (rowCount == 10) {
s.close();
}
}
@Override
public void onException(Statement s, Exception e) {
result.getResultsReceiver().exceptionOccurred(e);
}
@Override
public void onComplete(Statement s) {
result.getResultsReceiver().receiveResults(rowCount);
}
}, new RequestOptions().continuous(true));
assertEquals(10, result.get().intValue());
stmt = this.internalConnection.createStatement();
ResultSet rs = stmt.executeQuery("select count(*) from t");
rs.next();
assertEquals(2, rs.getInt(1));
}
use of org.teiid.client.util.ResultsFuture in project teiid by teiid.
the class TestAsynch method testAsynchContinuousNonEmpty.
@Test
public void testAsynchContinuousNonEmpty() throws Exception {
Statement stmt = this.internalConnection.createStatement();
TeiidStatement ts = stmt.unwrap(TeiidStatement.class);
final ResultsFuture<Integer> result = new ResultsFuture<Integer>();
ts.submitExecute("select 1", new ContinuousStatementCallback() {
int execCount;
@Override
public void onRow(Statement s, ResultSet rs) throws SQLException {
assertEquals(0, rs.unwrap(TeiidResultSet.class).available());
s.close();
}
@Override
public void onException(Statement s, Exception e) {
result.getResultsReceiver().exceptionOccurred(e);
}
@Override
public void onComplete(Statement s) {
result.getResultsReceiver().receiveResults(execCount);
}
@Override
public void beforeNextExecution(Statement s) throws SQLException {
execCount++;
}
}, new RequestOptions().continuous(true));
assertEquals(0, result.get().intValue());
}
Aggregations