Home / File/ BaseChannelTest.java — netty Source File

BaseChannelTest.java — netty Source File

Architecture documentation for BaseChannelTest.java, a java file in the netty codebase.

File java Buffer Search 1 classes

Entity Profile

Relationship Graph

Source Code

/*
 * Copyright 2012 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.channel;

import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.local.LocalChannel;
import io.netty.channel.local.LocalIoHandler;
import io.netty.channel.local.LocalServerChannel;

import static org.junit.jupiter.api.Assertions.assertEquals;

class BaseChannelTest {

    private final LoggingHandler loggingHandler;

    BaseChannelTest() {
        loggingHandler = new LoggingHandler();
    }

    ServerBootstrap getLocalServerBootstrap() {
        EventLoopGroup serverGroup = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory());
        ServerBootstrap sb = new ServerBootstrap();
        sb.group(serverGroup);
        sb.channel(LocalServerChannel.class);
        sb.childHandler(new ChannelInitializer<LocalChannel>() {
            @Override
            public void initChannel(LocalChannel ch) throws Exception {
            }
        });

        return sb;
    }

    Bootstrap getLocalClientBootstrap() {
        EventLoopGroup clientGroup = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory());
        Bootstrap cb = new Bootstrap();
        cb.channel(LocalChannel.class);
        cb.group(clientGroup);

        cb.handler(loggingHandler);

        return cb;
    }

    static ByteBuf createTestBuf(int len) {
        ByteBuf buf = Unpooled.buffer(len, len);
        buf.setIndex(0, len);
        return buf;
    }

    void assertLog(String firstExpected, String... otherExpected) {
        String actual = loggingHandler.getLog();
        if (firstExpected.equals(actual)) {
            return;
        }
        for (String e: otherExpected) {
            if (e.equals(actual)) {
                return;
            }
        }

        // Let the comparison fail with the first expectation.
        assertEquals(firstExpected, actual);
    }

    void clearLog() {
        loggingHandler.clear();
    }

    void setInterest(LoggingHandler.Event... events) {
        loggingHandler.setInterest(events);
    }

}

Domain

Subdomains

Classes

Frequently Asked Questions

What does BaseChannelTest.java do?
BaseChannelTest.java is a source file in the netty codebase, written in java. It belongs to the Buffer domain, Search subdomain.
Where is BaseChannelTest.java in the architecture?
BaseChannelTest.java is located at transport/src/test/java/io/netty/channel/BaseChannelTest.java (domain: Buffer, subdomain: Search, directory: transport/src/test/java/io/netty/channel).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free