use of com.facebook.presto.Session in project presto by prestodb.
the class TestResetSessionTask method test.
@Test
public void test() throws Exception {
Session session = testSessionBuilder(metadata.getSessionPropertyManager()).setSystemProperty("foo", "bar").setCatalogSessionProperty(CATALOG_NAME, "baz", "blah").build();
QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "reset foo", session, URI.create("fake://uri"), false, transactionManager, accessControl, executor, metadata);
getFutureValue(new ResetSessionTask().execute(new ResetSession(QualifiedName.of(CATALOG_NAME, "baz")), transactionManager, metadata, accessControl, stateMachine, emptyList()));
Set<String> sessionProperties = stateMachine.getResetSessionProperties();
assertEquals(sessionProperties, ImmutableSet.of("catalog.baz"));
}
use of com.facebook.presto.Session in project presto by prestodb.
the class TestRollbackTask method testRollback.
@Test
public void testRollback() throws Exception {
TransactionManager transactionManager = createTestTransactionManager();
AccessControl accessControl = new AccessControlManager(transactionManager);
Session session = sessionBuilder().setTransactionId(transactionManager.beginTransaction(false)).build();
QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "ROLLBACK", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
assertTrue(stateMachine.getSession().getTransactionId().isPresent());
assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
getFutureValue(new RollbackTask().execute(new Rollback(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
assertTrue(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
assertFalse(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
use of com.facebook.presto.Session in project presto by prestodb.
the class TestRollbackTask method testNoTransactionRollback.
@Test
public void testNoTransactionRollback() throws Exception {
TransactionManager transactionManager = createTestTransactionManager();
AccessControl accessControl = new AccessControlManager(transactionManager);
Session session = sessionBuilder().build();
QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "ROLLBACK", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
try {
try {
getFutureValue(new RollbackTask().execute(new Rollback(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
fail();
} catch (CompletionException e) {
throw Throwables.propagate(e.getCause());
}
} catch (PrestoException e) {
assertEquals(e.getErrorCode(), NOT_IN_TRANSACTION.toErrorCode());
}
assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
assertFalse(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
use of com.facebook.presto.Session in project presto by prestodb.
the class TestPrepareTask method testPrepareNameExists.
@Test
public void testPrepareNameExists() {
Session session = testSessionBuilder().addPreparedStatement("my_query", "SELECT bar, baz from foo").build();
Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo")));
String sqlString = "PREPARE my_query FROM SELECT * FROM foo";
Map<String, String> statements = executePrepare("my_query", query, sqlString, session);
assertEquals(statements, ImmutableMap.of("my_query", "SELECT *\nFROM\n foo\n"));
}
use of com.facebook.presto.Session in project presto by prestodb.
the class TestQueryQueueDefinition method testNameExpansion.
@Test
public void testNameExpansion() {
Session session = TestingSession.testSessionBuilder().setIdentity(new Identity("bob", Optional.empty())).setSource("the-internet").build();
QueryQueueDefinition definition = new QueryQueueDefinition("user.${USER}", 1, 1);
assertEquals(definition.getExpandedTemplate(session), "user.bob");
definition = new QueryQueueDefinition("source.${SOURCE}", 1, 1);
assertEquals(definition.getExpandedTemplate(session), "source.the-internet");
definition = new QueryQueueDefinition("${USER}.${SOURCE}", 1, 1);
assertEquals(definition.getExpandedTemplate(session), "bob.the-internet");
definition = new QueryQueueDefinition("global", 1, 1);
assertEquals(definition.getExpandedTemplate(session), "global");
}
Aggregations