use of io.crate.action.sql.SessionContext in project crate by crate.
the class PostgresWireProtocolTest method testCrateServerVersionIsReceivedOnStartup.
@Test
public void testCrateServerVersionIsReceivedOnStartup() throws Exception {
PostgresWireProtocol ctx = new PostgresWireProtocol(sqlOperations, sessionContext -> AccessControl.DISABLED, new AlwaysOKAuthentication(userName -> User.CRATE_USER), null);
channel = new EmbeddedChannel(ctx.decoder, ctx.handler);
ByteBuf buf = Unpooled.buffer();
ClientMessages.sendStartupMessage(buf, "doc");
channel.writeInbound(buf);
channel.releaseInbound();
ByteBuf respBuf;
respBuf = channel.readOutbound();
try {
// Auth OK
assertThat((char) respBuf.readByte(), is('R'));
} finally {
respBuf.release();
}
respBuf = channel.readOutbound();
try {
// ParameterStatus
assertThat((char) respBuf.readByte(), is('S'));
// length
respBuf.readInt();
String key = PostgresWireProtocol.readCString(respBuf);
String value = PostgresWireProtocol.readCString(respBuf);
assertThat(key, is("crate_version"));
assertThat(value, is(Version.CURRENT.externalNumber()));
} finally {
respBuf.release();
}
}
use of io.crate.action.sql.SessionContext in project crate by crate.
the class PostgresWireProtocolTest method testHandleEmptySimpleQuery.
@Test
public void testHandleEmptySimpleQuery() throws Exception {
PostgresWireProtocol ctx = new PostgresWireProtocol(mock(SQLOperations.class), sessionContext -> AccessControl.DISABLED, new AlwaysOKAuthentication(userName -> null), null);
channel = new EmbeddedChannel(ctx.decoder, ctx.handler);
ByteBuf buffer = Unpooled.buffer();
try {
Messages.writeCString(buffer, ";".getBytes(StandardCharsets.UTF_8));
ctx.handleSimpleQuery(buffer, new DelayableWriteChannel(channel));
} finally {
buffer.release();
}
ByteBuf firstResponse = channel.readOutbound();
byte[] responseBytes = new byte[5];
try {
firstResponse.readBytes(responseBytes);
// EmptyQueryResponse: 'I' | int32 len
assertThat(responseBytes, is(new byte[] { 'I', 0, 0, 0, 4 }));
} finally {
firstResponse.release();
}
ByteBuf secondResponse = channel.readOutbound();
try {
responseBytes = new byte[6];
secondResponse.readBytes(responseBytes);
// ReadyForQuery: 'Z' | int32 len | 'I'
assertThat(responseBytes, is(new byte[] { 'Z', 0, 0, 0, 5, 'I' }));
} finally {
secondResponse.release();
}
}
use of io.crate.action.sql.SessionContext in project crate by crate.
the class UpdatePlanner method createCollectAndMerge.
private static ExecutionPlan createCollectAndMerge(PlannerContext plannerCtx, TableInfo tableInfo, Reference idReference, Projection updateProjection, WhereClause where, int numOutPuts, int maxRowsPerNode, Projection... mergeProjections) {
SessionContext sessionContext = plannerCtx.transactionContext().sessionContext();
Routing routing = plannerCtx.allocateRouting(tableInfo, where, RoutingProvider.ShardSelection.PRIMARIES, sessionContext);
RoutedCollectPhase collectPhase = new RoutedCollectPhase(plannerCtx.jobId(), plannerCtx.nextExecutionPhaseId(), "collect", routing, tableInfo.rowGranularity(), List.of(idReference), singletonList(updateProjection), Optimizer.optimizeCasts(where.queryOrFallback(), plannerCtx), DistributionInfo.DEFAULT_BROADCAST);
Collect collect = new Collect(collectPhase, TopN.NO_LIMIT, 0, numOutPuts, maxRowsPerNode, null);
return Merge.ensureOnHandler(collect, plannerCtx, List.of(mergeProjections));
}
use of io.crate.action.sql.SessionContext in project crate by crate.
the class AccessControlMayExecuteTest method test_reset_session_authorization_from_normal_user_succeeds.
@Test
public void test_reset_session_authorization_from_normal_user_succeeds() {
e.analyzer.analyze(SqlParser.createStatement("RESET SESSION AUTHORIZATION"), new SessionContext(superUser, user), ParamTypeHints.EMPTY);
assertThat(validationCallArguments.size(), is(0));
}
use of io.crate.action.sql.SessionContext in project crate by crate.
the class AccessControlMayExecuteTest method test_set_session_user_from_normal_user_to_default_succeeds.
@Test
public void test_set_session_user_from_normal_user_to_default_succeeds() {
e.analyzer.analyze(SqlParser.createStatement("SET SESSION AUTHORIZATION DEFAULT"), new SessionContext(superUser, user), ParamTypeHints.EMPTY);
assertThat(validationCallArguments.size(), is(0));
}
Aggregations