Search in sources :

Example 1 with Compressor

use of com.datastax.oss.protocol.internal.Compressor in project java-driver by datastax.

the class ChannelFactoryTestBase method setup.

@Before
public void setup() throws InterruptedException {
    MockitoAnnotations.initMocks(this);
    serverGroup = new DefaultEventLoopGroup(1);
    clientGroup = new DefaultEventLoopGroup(1);
    when(context.getConfig()).thenReturn(driverConfig);
    when(driverConfig.getDefaultProfile()).thenReturn(defaultProfile);
    when(defaultProfile.isDefined(DefaultDriverOption.AUTH_PROVIDER_CLASS)).thenReturn(false);
    when(defaultProfile.getDuration(DefaultDriverOption.CONNECTION_INIT_QUERY_TIMEOUT)).thenReturn(Duration.ofMillis(TIMEOUT_MILLIS));
    when(defaultProfile.getDuration(DefaultDriverOption.CONNECTION_SET_KEYSPACE_TIMEOUT)).thenReturn(Duration.ofMillis(TIMEOUT_MILLIS));
    when(defaultProfile.getInt(DefaultDriverOption.CONNECTION_MAX_REQUESTS)).thenReturn(1);
    when(defaultProfile.getDuration(DefaultDriverOption.HEARTBEAT_INTERVAL)).thenReturn(Duration.ofSeconds(30));
    when(defaultProfile.getDuration(DefaultDriverOption.CONNECTION_CONNECT_TIMEOUT)).thenReturn(Duration.ofSeconds(5));
    when(context.getProtocolVersionRegistry()).thenReturn(protocolVersionRegistry);
    when(context.getNettyOptions()).thenReturn(nettyOptions);
    when(nettyOptions.ioEventLoopGroup()).thenReturn(clientGroup);
    when(nettyOptions.channelClass()).thenAnswer((Answer<Object>) i -> LocalChannel.class);
    when(nettyOptions.allocator()).thenReturn(ByteBufAllocator.DEFAULT);
    when(context.getFrameCodec()).thenReturn(FrameCodec.defaultClient(new ByteBufPrimitiveCodec(ByteBufAllocator.DEFAULT), Compressor.none()));
    when(context.getSslHandlerFactory()).thenReturn(Optional.empty());
    when(context.getEventBus()).thenReturn(eventBus);
    when(context.getWriteCoalescer()).thenReturn(new PassThroughWriteCoalescer(null));
    when(context.getCompressor()).thenReturn(compressor);
    // Start local server
    ServerBootstrap serverBootstrap = new ServerBootstrap().group(serverGroup).channel(LocalServerChannel.class).localAddress(SERVER_ADDRESS.resolve()).childHandler(new ServerInitializer());
    ChannelFuture channelFuture = serverBootstrap.bind().sync();
    serverAcceptChannel = (LocalServerChannel) channelFuture.sync().channel();
}
Also used : LocalServerChannel(io.netty.channel.local.LocalServerChannel) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) RunWith(org.junit.runner.RunWith) TimeoutException(java.util.concurrent.TimeoutException) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) CompletableFuture(java.util.concurrent.CompletableFuture) NettyOptions(com.datastax.oss.driver.internal.core.context.NettyOptions) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) NodeMetricUpdater(com.datastax.oss.driver.internal.core.metrics.NodeMetricUpdater) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) MockitoAnnotations(org.mockito.MockitoAnnotations) Answer(org.mockito.stubbing.Answer) Compressor(com.datastax.oss.protocol.internal.Compressor) DefaultDriverOption(com.datastax.oss.driver.api.core.config.DefaultDriverOption) Message(com.datastax.oss.protocol.internal.Message) ByteBuf(io.netty.buffer.ByteBuf) ProtocolVersionRegistry(com.datastax.oss.driver.internal.core.ProtocolVersionRegistry) LocalChannel(io.netty.channel.local.LocalChannel) EventBus(com.datastax.oss.driver.internal.core.context.EventBus) ByteBufPrimitiveCodec(com.datastax.oss.driver.internal.core.protocol.ByteBufPrimitiveCodec) Duration(java.time.Duration) After(org.junit.After) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) ProtocolVersion(com.datastax.oss.driver.api.core.ProtocolVersion) Ready(com.datastax.oss.protocol.internal.response.Ready) Before(org.junit.Before) ChannelInitializer(io.netty.channel.ChannelInitializer) FrameCodec(com.datastax.oss.protocol.internal.FrameCodec) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Mockito.when(org.mockito.Mockito.when) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Assertions.fail(org.assertj.core.api.Assertions.fail) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) TestResponses(com.datastax.oss.driver.internal.core.TestResponses) Frame(com.datastax.oss.protocol.internal.Frame) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Optional(java.util.Optional) Startup(com.datastax.oss.protocol.internal.request.Startup) Options(com.datastax.oss.protocol.internal.request.Options) Collections(java.util.Collections) Exchanger(java.util.concurrent.Exchanger) ChannelFuture(io.netty.channel.ChannelFuture) LocalChannel(io.netty.channel.local.LocalChannel) ByteBufPrimitiveCodec(com.datastax.oss.driver.internal.core.protocol.ByteBufPrimitiveCodec) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Before(org.junit.Before)

Aggregations

ProtocolVersion (com.datastax.oss.driver.api.core.ProtocolVersion)1 DefaultDriverOption (com.datastax.oss.driver.api.core.config.DefaultDriverOption)1 DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)1 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)1 EndPoint (com.datastax.oss.driver.api.core.metadata.EndPoint)1 ProtocolVersionRegistry (com.datastax.oss.driver.internal.core.ProtocolVersionRegistry)1 TestResponses (com.datastax.oss.driver.internal.core.TestResponses)1 EventBus (com.datastax.oss.driver.internal.core.context.EventBus)1 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)1 NettyOptions (com.datastax.oss.driver.internal.core.context.NettyOptions)1 NodeMetricUpdater (com.datastax.oss.driver.internal.core.metrics.NodeMetricUpdater)1 ByteBufPrimitiveCodec (com.datastax.oss.driver.internal.core.protocol.ByteBufPrimitiveCodec)1 Compressor (com.datastax.oss.protocol.internal.Compressor)1 Frame (com.datastax.oss.protocol.internal.Frame)1 FrameCodec (com.datastax.oss.protocol.internal.FrameCodec)1 Message (com.datastax.oss.protocol.internal.Message)1 Options (com.datastax.oss.protocol.internal.request.Options)1 Startup (com.datastax.oss.protocol.internal.request.Startup)1 Ready (com.datastax.oss.protocol.internal.response.Ready)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1