Skip to content

Commit

Permalink
Make DeephavenSessionTestBase use NoLanguageDeephavenSession (#2811)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind authored Sep 7, 2022
1 parent d0cba48 commit 424f20a
Show file tree
Hide file tree
Showing 21 changed files with 145 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,8 @@ public Collection<String> getImportStrings() {
public void updateVersionString() {
versionString = UuidCreator.toString(UuidCreator.getRandomBased());
}

public void updateVersionString(String version) {
versionString = version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.deephaven.io.log.LogLevel;
import io.deephaven.io.logger.LogBuffer;
import io.deephaven.io.logger.LogBufferOutputStream;
import io.deephaven.server.console.SessionToExecutionStateModule;
import io.deephaven.server.console.groovy.GroovyConsoleSessionModule;
import io.deephaven.server.console.python.PythonConsoleSessionModule;
import io.deephaven.server.console.python.PythonGlobalScopeModule;
Expand Down Expand Up @@ -48,6 +49,7 @@ public class EmbeddedServer {
JettyServerModule.class,
PythonConsoleSessionModule.class,
GroovyConsoleSessionModule.class,
SessionToExecutionStateModule.class,
})
public interface PythonServerComponent extends DeephavenApiServerComponent {
@Component.Builder
Expand Down
1 change: 1 addition & 0 deletions server/jetty/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
implementation project(':grpc-java:grpc-mtls')

testImplementation project(':server-test')
testImplementation TestTools.projectDependency(project, ':server')

testRuntimeOnly project(':log-to-slf4j')
Classpaths.inheritSlf4j(project, 'slf4j-simple', 'testRuntimeOnly')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import dagger.BindsInstance;
import dagger.Component;
import io.deephaven.server.console.SessionToExecutionStateModule;
import io.deephaven.server.console.groovy.GroovyConsoleSessionModule;
import io.deephaven.server.console.python.PythonConsoleSessionModule;
import io.deephaven.server.console.python.PythonGlobalScopeCopyModule;
Expand All @@ -28,6 +29,7 @@
JettyServerModule.class,
PythonConsoleSessionModule.class,
GroovyConsoleSessionModule.class,
SessionToExecutionStateModule.class,
})
public interface JettyServerComponent extends DeephavenApiServerComponent {
@Component.Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dagger.Module;
import dagger.Provides;
import io.deephaven.server.arrow.ArrowModule;
import io.deephaven.server.runner.ExecutionContextUnitTestModule;
import io.deephaven.server.session.SessionModule;
import io.deephaven.server.test.AuthTestModule;
import io.deephaven.server.test.FlightMessageRoundTripTest;
Expand All @@ -30,7 +31,8 @@ static JettyConfig providesJettyConfig() {
SessionModule.class,
AuthTestModule.class,
JettyServerModule.class,
JettyTestConfig.class
JettyTestConfig.class,
ExecutionContextUnitTestModule.class,
})
public interface JettyTestComponent extends TestComponent {
}
Expand Down
1 change: 1 addition & 0 deletions server/netty/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
implementation project(':grpc-java:grpc-mtls')

testImplementation project(':server-test')
testImplementation TestTools.projectDependency(project, ':server')

testRuntimeOnly project(':log-to-slf4j')
Classpaths.inheritSlf4j(project, 'slf4j-simple', 'testRuntimeOnly')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import dagger.BindsInstance;
import dagger.Component;
import io.deephaven.server.console.SessionToExecutionStateModule;
import io.deephaven.server.console.groovy.GroovyConsoleSessionModule;
import io.deephaven.server.console.python.PythonConsoleSessionModule;
import io.deephaven.server.console.python.PythonGlobalScopeCopyModule;
Expand All @@ -28,6 +29,7 @@
NettyServerModule.class,
PythonConsoleSessionModule.class,
GroovyConsoleSessionModule.class,
SessionToExecutionStateModule.class,
})
public interface NettyServerComponent extends DeephavenApiServerComponent {
@Component.Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dagger.Module;
import dagger.Provides;
import io.deephaven.server.arrow.ArrowModule;
import io.deephaven.server.runner.ExecutionContextUnitTestModule;
import io.deephaven.server.session.SessionModule;
import io.deephaven.server.test.AuthTestModule;
import io.deephaven.server.test.FlightMessageRoundTripTest;
Expand All @@ -30,7 +31,8 @@ static NettyConfig providesNettyConfig() {
SessionModule.class,
AuthTestModule.class,
NettyServerModule.class,
NettyTestConfig.class
NettyTestConfig.class,
ExecutionContextUnitTestModule.class,
})
public interface NettyTestComponent extends TestComponent {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.server.console;

import dagger.Module;
import dagger.Provides;
import dagger.multibindings.IntoMap;
import dagger.multibindings.StringKey;
import io.deephaven.engine.util.NoLanguageDeephavenSession;
import io.deephaven.engine.util.ScriptSession;
import io.deephaven.server.console.groovy.InitScriptsModule;

@Module(includes = InitScriptsModule.ServiceLoader.class)
public class NoConsoleSessionModule {
@Provides
@IntoMap
@StringKey("none")
ScriptSession bindScriptSession(NoLanguageDeephavenSession noLanguageSession) {
return noLanguageSession;
}

@Provides
NoLanguageDeephavenSession bindNoLanguageSession() {
return new NoLanguageDeephavenSession();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.deephaven.server.console;

import dagger.Module;
import dagger.Provides;
import io.deephaven.engine.context.ExecutionContext;
import io.deephaven.engine.util.ScriptSession;

@Module
public class SessionToExecutionStateModule {
@Provides
ExecutionContext bindExecutionContext(ScriptSession session) {
return session.getExecutionContext();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import io.deephaven.auth.AuthenticationRequestHandler;
import io.deephaven.configuration.Configuration;
import io.deephaven.engine.context.ExecutionContext;
import io.deephaven.engine.table.impl.perf.QueryPerformanceRecorder;
import io.deephaven.engine.table.impl.perf.UpdatePerformanceTracker;
import io.deephaven.engine.table.impl.util.MemoryTableLoggers;
Expand Down Expand Up @@ -51,6 +52,7 @@ public class DeephavenApiServer {
private final UriResolvers uriResolvers;
private final SessionService sessionService;
private final Map<String, AuthenticationRequestHandler> authenticationHandlers;
private final Provider<ExecutionContext> executionContextProvider;

@Inject
public DeephavenApiServer(
Expand All @@ -62,7 +64,8 @@ public DeephavenApiServer(
final ApplicationInjector applicationInjector,
final UriResolvers uriResolvers,
final SessionService sessionService,
final Map<String, AuthenticationRequestHandler> authenticationHandlers) {
final Map<String, AuthenticationRequestHandler> authenticationHandlers,
final Provider<ExecutionContext> executionContextProvider) {
this.server = server;
this.ugp = ugp;
this.logInit = logInit;
Expand All @@ -72,6 +75,7 @@ public DeephavenApiServer(
this.uriResolvers = uriResolvers;
this.sessionService = sessionService;
this.authenticationHandlers = authenticationHandlers;
this.executionContextProvider = executionContextProvider;
}

@VisibleForTesting
Expand Down Expand Up @@ -162,6 +166,8 @@ public void join() throws InterruptedException {
void startForUnitTests() throws Exception {
pluginRegistration.registerAll();
applicationInjector.run();
executionContextProvider.get().getQueryLibrary().updateVersionString("DEFAULT");

log.info().append("Starting server...").endl();
server.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import dagger.BindsInstance;
import dagger.Component;
import io.deephaven.server.console.SessionToExecutionStateModule;
import io.deephaven.server.console.groovy.GroovyConsoleSessionModule;
import io.deephaven.server.log.LogModule;
import io.grpc.ManagedChannelBuilder;
Expand All @@ -18,7 +19,8 @@
DeephavenApiServerModule.class,
LogModule.class,
GroovyConsoleSessionModule.class,
ServerBuilderInProcessModule.class
ServerBuilderInProcessModule.class,
SessionToExecutionStateModule.class,
})
public interface DeephavenApiServerInProcessGroovyComponent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import dagger.BindsInstance;
import dagger.Component;
import io.deephaven.server.console.SessionToExecutionStateModule;
import io.deephaven.server.console.python.PythonConsoleSessionModule;
import io.deephaven.server.console.python.PythonGlobalScopeCopyModule;
import io.deephaven.server.log.LogModule;
Expand All @@ -20,7 +21,8 @@
LogModule.class,
PythonConsoleSessionModule.class,
PythonGlobalScopeCopyModule.class,
ServerBuilderInProcessModule.class
ServerBuilderInProcessModule.class,
SessionToExecutionStateModule.class,
})
public interface DeephavenApiServerInProcessPythonComponent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ public static <T> ExportObject<T> wrapAsExport(final T export) {

@AssistedInject
public SessionState(final Scheduler scheduler,
final Provider<ScriptSession> scriptSessionProvider,
final Provider<ExecutionContext> executionContextProvider,
@Assisted final AuthContext authContext) {
this.sessionId = UuidCreator.toString(UuidCreator.getRandomBased());
this.logPrefix = "SessionState{" + sessionId + "}: ";
this.scheduler = scheduler;
this.authContext = authContext;
this.executionContext = scriptSessionProvider.get().getExecutionContext();
this.executionContext = executionContextProvider.get();
log.info().append(logPrefix).append("session initialized").endl();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package io.deephaven.server.appmode;

import io.deephaven.engine.context.ExecutionContext;
import io.deephaven.engine.liveness.LivenessScopeStack;
import io.deephaven.engine.util.NoLanguageDeephavenSession;
import io.deephaven.engine.util.ScriptSession;
Expand Down Expand Up @@ -42,7 +43,7 @@ public void setup() {
livenessScope = LivenessScopeStack.open();
scheduler = new TestControlledScheduler();
sessionService = new SessionService(scheduler,
authContext -> new SessionState(scheduler, NoLanguageDeephavenSession::new, authContext),
authContext -> new SessionState(scheduler, ExecutionContext::createForUnitTests, authContext),
TOKEN_EXPIRE_MS, Optional.empty(), Collections.emptyMap());
applicationServiceGrpcImpl = new ApplicationServiceGrpcImpl(scheduler, sessionService,
new TypeLookup(ObjectTypeLookup.NoOp.INSTANCE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
*/
package io.deephaven.server.runner;

import dagger.BindsInstance;
import dagger.Component;
import io.deephaven.engine.context.ExecutionContext;
import io.deephaven.engine.updategraph.UpdateGraphProcessor;
import io.deephaven.engine.liveness.LivenessScope;
import io.deephaven.engine.liveness.LivenessScopeStack;
import io.deephaven.io.logger.LogBuffer;
import io.deephaven.io.logger.LogBufferGlobal;
import io.deephaven.proto.DeephavenChannel;
import io.deephaven.server.console.NoConsoleSessionModule;
import io.deephaven.server.log.LogModule;
import io.deephaven.util.SafeCloseable;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
Expand All @@ -17,17 +22,52 @@
import org.junit.Before;
import org.junit.Rule;

import javax.inject.Named;
import javax.inject.Singleton;
import java.io.PrintStream;
import java.util.concurrent.TimeUnit;

/**
* Manages a single instance of {@link DeephavenApiServer}.
*/
public abstract class DeephavenApiServerTestBase {
@Singleton
@Component(modules = {
DeephavenApiServerModule.class,
LogModule.class,
NoConsoleSessionModule.class,
ServerBuilderInProcessModule.class,
ExecutionContextUnitTestModule.class,
})
public interface TestComponent {

DeephavenApiServer getServer();

ManagedChannelBuilder<?> channelBuilder();

@Component.Builder
interface Builder {

@BindsInstance
Builder withSchedulerPoolSize(@Named("scheduler.poolSize") int numThreads);

@BindsInstance
Builder withSessionTokenExpireTmMs(@Named("session.tokenExpireMs") long tokenExpireMs);

@BindsInstance
Builder withOut(@Named("out") PrintStream out);

@BindsInstance
Builder withErr(@Named("err") PrintStream err);

TestComponent build();
}
}

@Rule
public final GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();

private DeephavenApiServerInProcessGroovyComponent serverComponent;
private TestComponent serverComponent;
private LogBuffer logBuffer;
private DeephavenApiServer server;
private SafeCloseable scopeCloseable;
Expand All @@ -40,8 +80,7 @@ public void setUp() throws Exception {
logBuffer = new LogBuffer(128);
LogBufferGlobal.setInstance(logBuffer);

serverComponent = DaggerDeephavenApiServerInProcessGroovyComponent
.builder()
serverComponent = DaggerDeephavenApiServerTestBase_TestComponent.builder()
.withSchedulerPoolSize(4)
.withSessionTokenExpireTmMs(sessionTokenExpireTmMs())
.withOut(System.out)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.deephaven.server.runner;

import dagger.Module;
import dagger.Provides;
import io.deephaven.engine.context.ExecutionContext;

import javax.inject.Singleton;

@Module
public class ExecutionContextUnitTestModule {
@Provides
@Singleton
public ExecutionContext provideExecutionContext() {
return ExecutionContext.createForUnitTests();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package io.deephaven.server.session;

import io.deephaven.base.verify.Assert;
import io.deephaven.engine.context.ExecutionContext;
import io.deephaven.engine.liveness.LivenessScopeStack;
import io.deephaven.engine.util.NoLanguageDeephavenSession;
import io.deephaven.server.util.TestControlledScheduler;
Expand All @@ -30,7 +31,7 @@ public void setup() {
livenessScope = LivenessScopeStack.open();
scheduler = new TestControlledScheduler();
sessionService = new SessionService(scheduler,
authContext -> new SessionState(scheduler, NoLanguageDeephavenSession::new, authContext),
authContext -> new SessionState(scheduler, ExecutionContext::createForUnitTests, authContext),
TOKEN_EXPIRE_MS, Optional.empty(), Collections.emptyMap());
}

Expand Down
Loading

0 comments on commit 424f20a

Please sign in to comment.