public static ExecutionVenueNioClient createClient(String connectionString, NioConfig cfg) { GeoIPLocator geo = Mockito.mock(GeoIPLocator.class); SocketRMIMarshaller marshaller = new SocketRMIMarshaller( geo, new CommonNameCertInfoExtractor(), new DefaultSocketTimeResolver()); IdentityResolverFactory factory = new IdentityResolverFactory(); factory.setIdentityResolver(Mockito.mock(IdentityResolver.class)); NioLogger logger = new NioLogger("ALL"); ExecutionVenueNioClient client = new ExecutionVenueNioClient( logger, cfg, new HessianObjectIOFactory(), new ClientConnectedObjectManager(), null, connectionString, new JMXReportingThreadPoolExecutor( 30, 60, 0, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()), new JMXReportingThreadPoolExecutor( 30, 60, 0, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()), new DNSBasedAddressResolver()); client.setMarshaller(marshaller); return client; }
public static ExecutionVenueNioServer createServer(byte serverVersion, TlsNioConfig cfg) { CougarProtocol.setMinServerProtocolVersion(serverVersion); CougarProtocol.setMaxServerProtocolVersion(serverVersion); final ExecutionVenueNioServer server = new ExecutionVenueNioServer(); server.setNioConfig(cfg); SocketTransportCommandProcessor cmdProcessor = new SocketTransportCommandProcessor(); cmdProcessor.setIdentityResolverFactory(new IdentityResolverFactory()); Executor executor = new Executor() { @Override public void execute(Runnable command) { Thread t = new Thread(command); t.start(); } }; GeoIPLocator geo = Mockito.mock(GeoIPLocator.class); SocketRMIMarshaller marshaller = new SocketRMIMarshaller( geo, new CommonNameCertInfoExtractor(), new DefaultSocketTimeResolver(true)); IdentityResolverFactory identityResolverFactory = new IdentityResolverFactory(); identityResolverFactory.setIdentityResolver(Mockito.mock(IdentityResolver.class)); ExecutionVenue ev = new ExecutionVenue() { @Override public void registerOperation( String namespace, OperationDefinition def, Executable executable, ExecutionTimingRecorder recorder, long maxExecutionTime) {} @Override public OperationDefinition getOperationDefinition(OperationKey key) { return AbstractClientTest.OPERATION_DEFINITION; } @Override public Set<OperationKey> getOperationKeys() { return null; } @Override public void execute( ExecutionContext ctx, OperationKey key, Object[] args, ExecutionObserver observer, TimeConstraints timeConstraints) { switch (Integer.parseInt(args[1].toString())) { case COMMAND_STOP_SERVER: logger.log(Level.INFO, "Stopping server"); server.stop(); break; case COMMAND_SLEEP_60S: logger.log(Level.INFO, "Sleeping for 60s"); try { Thread.sleep(60000L); } catch (Exception e) { } case COMMAND_ECHO_ARG2: observer.onResult(new ExecutionResult(args[2])); break; case COMMAND_FRAMEWORK_ERROR: observer.onResult( new ExecutionResult( new CougarServiceException( ServerFaultCode.FrameworkError, AbstractClientTest.BANG))); break; } } public void execute( final ExecutionContext ctx, final OperationKey key, final Object[] args, final ExecutionObserver observer, Executor executor, final TimeConstraints timeConstraints) { executor.execute( new Runnable() { @Override public void run() { execute(ctx, key, args, observer, timeConstraints); } }); } @Override public void setPreProcessors(List<ExecutionPreProcessor> preProcessorList) {} @Override public void setPostProcessors(List<ExecutionPostProcessor> preProcessorList) {} }; cmdProcessor.setExecutor(executor); cmdProcessor.setMarshaller(marshaller); cmdProcessor.setExecutionVenue(ev); ServiceBindingDescriptor desc = new SocketBindingDescriptor() { @Override public OperationBindingDescriptor[] getOperationBindings() { return new OperationBindingDescriptor[] { new SocketOperationBindingDescriptor( AbstractClientTest.OPERATION_DEFINITION.getOperationKey()) }; } @Override public ServiceVersion getServiceVersion() { return AbstractClientTest.OPERATION_DEFINITION.getOperationKey().getVersion(); } @Override public String getServiceName() { return AbstractClientTest.OPERATION_DEFINITION.getOperationKey().getServiceName(); } @Override public Protocol getServiceProtocol() { return Protocol.SOCKET; } }; cmdProcessor.bind(desc); cmdProcessor.onCougarStart(); final NioLogger nioLogger = new NioLogger("ALL"); ExecutionVenueServerHandler handler = new ExecutionVenueServerHandler(nioLogger, cmdProcessor, new HessianObjectIOFactory()); server.setServerHandler(handler); IoSessionManager sessionManager = new IoSessionManager(); sessionManager.setNioLogger(nioLogger); sessionManager.setMaxTimeToWaitForRequestCompletion(5000); server.setSessionManager(sessionManager); return server; }