use of org.elasticsearch.common.breaker.NoopCircuitBreaker in project crate by crate.
the class SqlHttpHandlerTest method testSessionSettingsArePreservedAcrossRequests.
@Test
public void testSessionSettingsArePreservedAcrossRequests() {
User dummyUser = User.of("dummy");
var sessionConext = new SessionContext(dummyUser);
var mockedSession = mock(Session.class);
when(mockedSession.sessionContext()).thenReturn(sessionConext);
var mockedSqlOperations = mock(SQLOperations.class);
when(mockedSqlOperations.createSession(null, dummyUser)).thenReturn(mockedSession);
var mockedRequest = mock(FullHttpRequest.class);
when(mockedRequest.headers()).thenReturn(new DefaultHttpHeaders());
SqlHttpHandler handler = new SqlHttpHandler(Settings.EMPTY, mockedSqlOperations, (s) -> new NoopCircuitBreaker("dummy"), userName -> dummyUser, sessionContext -> AccessControl.DISABLED, Netty4CorsConfigBuilder.forAnyOrigin().build());
// 1st call to ensureSession creates a session instance bound to 'dummyUser'
var session = handler.ensureSession(mockedRequest);
verify(mockedRequest, atLeast(1)).headers();
assertThat(session.sessionContext().authenticatedUser(), is(dummyUser));
assertThat(session.sessionContext().searchPath().currentSchema(), containsString("doc"));
assertTrue(session.sessionContext().isHashJoinEnabled());
// modify the session settings
session.sessionContext().setSearchPath("dummy_path");
session.sessionContext().setHashJoinEnabled(false);
// test that the 2nd call to ensureSession will retrieve the session settings modified previously
session = handler.ensureSession(mockedRequest);
assertFalse(session.sessionContext().isHashJoinEnabled());
assertThat(session.sessionContext().searchPath().currentSchema(), containsString("dummy_path"));
}
use of org.elasticsearch.common.breaker.NoopCircuitBreaker in project crate by crate.
the class InboundPipelineTests method testDecodeExceptionIsPropagated.
public void testDecodeExceptionIsPropagated() throws IOException {
BiConsumer<TcpChannel, InboundMessage> messageHandler = (c, m) -> {
};
final StatsTracker statsTracker = new StatsTracker();
final LongSupplier millisSupplier = () -> TimeValue.nsecToMSec(System.nanoTime());
final InboundDecoder decoder = new InboundDecoder(Version.CURRENT, PageCacheRecycler.NON_RECYCLING_INSTANCE);
final Supplier<CircuitBreaker> breaker = () -> new NoopCircuitBreaker("test");
final InboundAggregator aggregator = new InboundAggregator(breaker, (Predicate<String>) action -> true);
final InboundPipeline pipeline = new InboundPipeline(statsTracker, millisSupplier, decoder, aggregator, messageHandler);
try (BytesStreamOutput streamOutput = new BytesStreamOutput()) {
String actionName = "actionName";
final Version invalidVersion = Version.V_3_2_0;
final String value = randomAlphaOfLength(1000);
final boolean isRequest = randomBoolean();
final long requestId = randomNonNegativeLong();
OutboundMessage message;
if (isRequest) {
message = new OutboundMessage.Request(new TestRequest(value), invalidVersion, actionName, requestId, false, false);
} else {
message = new OutboundMessage.Response(new TestResponse(value), invalidVersion, requestId, false, false);
}
final BytesReference reference = message.serialize(streamOutput);
try (ReleasableBytesReference releasable = ReleasableBytesReference.wrap(reference)) {
expectThrows(IllegalStateException.class, () -> pipeline.handleBytes(new FakeTcpChannel(), releasable));
}
// Pipeline cannot be reused after uncaught exception
final IllegalStateException ise = expectThrows(IllegalStateException.class, () -> pipeline.handleBytes(new FakeTcpChannel(), ReleasableBytesReference.wrap(BytesArray.EMPTY)));
assertEquals("Pipeline state corrupted by uncaught exception", ise.getMessage());
}
}
use of org.elasticsearch.common.breaker.NoopCircuitBreaker in project crate by crate.
the class SqlHttpHandlerTest method testDefaultUserIfHttpHeaderNotPresent.
@Test
public void testDefaultUserIfHttpHeaderNotPresent() {
SqlHttpHandler handler = new SqlHttpHandler(Settings.EMPTY, mock(SQLOperations.class), (s) -> new NoopCircuitBreaker("dummy"), userName -> {
if (userName.equals("crate")) {
return User.CRATE_USER;
}
return null;
}, sessionContext -> AccessControl.DISABLED, Netty4CorsConfigBuilder.forAnyOrigin().build());
User user = handler.userFromAuthHeader(null);
assertThat(user, is(User.CRATE_USER));
}
use of org.elasticsearch.common.breaker.NoopCircuitBreaker in project crate by crate.
the class SqlHttpHandlerTest method testSettingUserIfHttpHeaderNotPresent.
@Test
public void testSettingUserIfHttpHeaderNotPresent() {
Settings settings = Settings.builder().put(AuthSettings.AUTH_TRUST_HTTP_DEFAULT_HEADER.getKey(), "trillian").build();
SqlHttpHandler handler = new SqlHttpHandler(settings, mock(SQLOperations.class), (s) -> new NoopCircuitBreaker("dummy"), User::of, sessionContext -> AccessControl.DISABLED, Netty4CorsConfigBuilder.forAnyOrigin().build());
User user = handler.userFromAuthHeader(null);
assertThat(user.name(), is("trillian"));
}
use of org.elasticsearch.common.breaker.NoopCircuitBreaker in project crate by crate.
the class OutboundHandlerTests method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
channel = new FakeTcpChannel(randomBoolean(), buildNewFakeTransportAddress().address(), buildNewFakeTransportAddress().address());
TransportAddress transportAddress = buildNewFakeTransportAddress();
node = new DiscoveryNode("", transportAddress, Version.CURRENT);
StatsTracker statsTracker = new StatsTracker();
handler = new OutboundHandler("node", Version.CURRENT, statsTracker, threadPool, BigArrays.NON_RECYCLING_INSTANCE);
final LongSupplier millisSupplier = () -> TimeValue.nsecToMSec(System.nanoTime());
final InboundDecoder decoder = new InboundDecoder(Version.CURRENT, PageCacheRecycler.NON_RECYCLING_INSTANCE);
final Supplier<CircuitBreaker> breaker = () -> new NoopCircuitBreaker("test");
final InboundAggregator aggregator = new InboundAggregator(breaker, (Predicate<String>) action -> true);
pipeline = new InboundPipeline(statsTracker, millisSupplier, decoder, aggregator, (c, m) -> {
try (BytesStreamOutput streamOutput = new BytesStreamOutput()) {
Streams.copy(m.openOrGetStreamInput(), streamOutput);
message.set(new Tuple<>(m.getHeader(), streamOutput.bytes()));
} catch (IOException e) {
throw new AssertionError(e);
}
});
}
Aggregations