类io.netty.util.ResourceLeakDetector.Level源码实例Demo

下面列出了怎么用io.netty.util.ResourceLeakDetector.Level的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: turbo-rpc   文件: RestClientBenchmark.java
public static void main(String[] args) throws Exception {
	ResourceLeakDetector.setLevel(Level.DISABLED);
	// CtClass.debugDump = "d:/debugDump";

	// RestClientBenchmark clientBenchmark = new RestClientBenchmark();
	// System.out.println(clientBenchmark.createUser());
	// clientBenchmark.close();

	Options opt = new OptionsBuilder()//
			.include(RestClientBenchmark.class.getSimpleName())//
			.warmupIterations(5)//
			.measurementIterations(5)//
			.threads(CONCURRENCY)//
			.forks(1)//
			.build();

	new Runner(opt).run();
}
 
源代码2 项目: grpc-nebula-java   文件: AltsTsiTest.java
@Before
public void setUp() throws Exception {
  ResourceLeakDetector.setLevel(Level.PARANOID);
  // Use MockAltsHandshakerStub for all the tests.
  AltsHandshakerOptions handshakerOptions = new AltsHandshakerOptions(null);
  MockAltsHandshakerStub clientStub = new MockAltsHandshakerStub();
  MockAltsHandshakerStub serverStub = new MockAltsHandshakerStub();
  client = new AltsHandshakerClient(clientStub, handshakerOptions);
  server = new AltsHandshakerClient(serverStub, handshakerOptions);
}
 
源代码3 项目: turbo-rpc   文件: RpcServerBenchmark.java
public static void main(String[] args) throws Exception {
	ResourceLeakDetector.setLevel(Level.DISABLED);
	// CtClass.debugDump = "d:/debugDump";

	try (TurboServer server = new TurboServer("shop", "auth");) {
		Map<Class<?>, Object> services = Map.of(UserService.class, new UserServiceServerImpl());
		server.registerService(services);

		/*
		 * server.addFirst(new RpcServerFilter() {
		 * 
		 * @Override public void onSend(Request request, Response response) { try {
		 * Tracer tracer = request.getTracer();
		 * 
		 * if (tracer != null) { response.setTracer(tracer); }
		 * 
		 * } catch (Exception e) { e.printStackTrace(); } }
		 * 
		 * @Override public boolean onRecive(Request request) { try { Tracer tracer =
		 * request.getTracer();
		 * 
		 * if (tracer != null) { RemoteContext.getClientAddress().toString();
		 * RemoteContext.getServerAddress().toString();
		 * RemoteContext.getServiceMethodName();
		 * 
		 * TracerContext.setTracer(tracer); } } catch (Exception e) {
		 * e.printStackTrace(); }
		 * 
		 * return true; }
		 * 
		 * @Override public void onError(Request request, Response response, Throwable
		 * throwable) { } });
		 */

		server.startRpcServer(new HostPort("127.0.0.1", 8080));
		server.waitUntilShutdown();
	}
}
 
源代码4 项目: turbo-rpc   文件: RestServerBenchmark.java
public static void main(String[] args) throws Exception {
	ResourceLeakDetector.setLevel(Level.DISABLED);
	// CtClass.debugDump = "d:/debugDump";

	try (TurboServer server = new TurboServer("shop", "auth");) {
		Map<Class<?>, Object> services = Map.of(UserService.class, new UserServiceServerImpl());
		server.registerService(services);

		server.startRestServer(new HostPort("0.0.0.0", 8080));
		server.waitUntilShutdown();
	}
}
 
源代码5 项目: rpc-benchmark   文件: Server.java
public static void main(String[] args) throws Exception {
	ResourceLeakDetector.setLevel(Level.DISABLED);

	try (TurboServer server = new TurboServer("shop", "auth");) {
		Map<Class<?>, Object> services = Map.of(TurboUserService.class, new TurboUserServiceServerImpl());
		server.registerService(services);

		server.startRestServer(new HostPort("benchmark-server", 8080));
		server.waitUntilShutdown();
	}
}
 
源代码6 项目: rpc-benchmark   文件: Client.java
public Client() {
	ResourceLeakDetector.setLevel(Level.DISABLED);

	client = new TurboClient("turbo-client.conf");

	try {
		client.register(TurboUserService.class);
		userService = client.getService(TurboUserService.class);
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
源代码7 项目: luna   文件: LunaSettings.java
/**
 * Please note as the leak detection levels get higher, the tradeoff is a <strong>substantial</strong>
 * performance loss. {@code PARANOID} should <strong>never</strong> be used in a production environment.
 */
public Level resourceLeakDetection() {
    switch (runtimeMode) {
        case PRODUCTION:
            return Level.DISABLED;
        case BENCHMARK:
            return Level.SIMPLE;
        case DEVELOPMENT:
            return Level.PARANOID;
        default:
            throw new IllegalStateException("Invalid runtime mode!");
    }
}
 
源代码8 项目: asteria-3.0   文件: NetworkBuilder.java
/**
 * Initializes this network handler effectively preparing the server to
 * listen for connections and handle network events.
 *
 * @param port
 *            the port that this network will be bound to.
 * @throws Exception
 *             if any issues occur while starting the network.
 */
public void initialize(int port) throws IOException {
    if (port != 43594 && port != 5555 && port != 43595)
        logger.warning("The preferred ports for Runescape servers are 43594, 5555, and 43595!");
    ResourceLeakDetector.setLevel(Server.DEBUG ? Level.PARANOID : NetworkConstants.RESOURCE_DETECTION);
    bootstrap.group(loopGroup);
    bootstrap.channel(NioServerSocketChannel.class);
    bootstrap.childHandler(channelInitializer);
    bootstrap.bind(port).syncUninterruptibly();
}
 
源代码9 项目: ProtocolSupport   文件: LeakDetectorSubCommand.java
@Override
public boolean handle(CommandSender sender, String[] args) {
	if (ResourceLeakDetector.isEnabled()) {
		ResourceLeakDetector.setLevel(Level.DISABLED);
		sender.sendMessage(ChatColor.YELLOW + "Disabled leak detector");
	} else {
		ResourceLeakDetector.setLevel(Level.PARANOID);
		sender.sendMessage(ChatColor.YELLOW + "Enabled leak detector");
	}
	return true;
}
 
源代码10 项目: qpid-jms   文件: NettyTcpTransportTest.java
@Ignore("Used for checking for transport level leaks, my be unstable on CI.")
@Test(timeout = 60 * 1000)
public void testSendToClosedTransportFailsButDoesNotLeak() throws Exception {
    Transport transport = null;

    ResourceLeakDetector.setLevel(Level.PARANOID);

    try (NettyEchoServer server = createEchoServer(createServerOptions())) {
        server.start();

        int port = server.getServerPort();
        URI serverLocation = new URI("tcp://localhost:" + port);

        for (int i = 0; i < 256; ++i) {
            transport = createTransport(serverLocation, testListener, createClientOptions());
            try {
                transport.connect(null, null);
                LOG.info("Connected to server:{} as expected.", serverLocation);
            } catch (Exception e) {
                fail("Should have connected to the server at " + serverLocation + " but got exception: " + e);
            }

            assertTrue(transport.isConnected());

            ByteBuf sendBuffer = transport.allocateSendBuffer(10 * 1024 * 1024);
            sendBuffer.writeBytes(new byte[] {0, 1, 2, 3, 4});

            transport.close();

            try {
                transport.writeAndFlush(sendBuffer);
                fail("Should throw on send of closed transport");
            } catch (IOException ex) {
            }
        }

        System.gc();
    }
}
 
源代码11 项目: grpc-java   文件: AltsTsiTest.java
@Before
public void setUp() throws Exception {
  ResourceLeakDetector.setLevel(Level.PARANOID);
  // Use MockAltsHandshakerStub for all the tests.
  AltsHandshakerOptions handshakerOptions = new AltsHandshakerOptions(null);
  MockAltsHandshakerStub clientStub = new MockAltsHandshakerStub();
  MockAltsHandshakerStub serverStub = new MockAltsHandshakerStub();
  client = new AltsHandshakerClient(clientStub, handshakerOptions);
  server = new AltsHandshakerClient(serverStub, handshakerOptions);
}
 
@Before
public void setUp() {
  ResourceLeakDetector.setLevel(Level.PARANOID);
}
 
源代码13 项目: grpc-nebula-java   文件: AltsChannelCrypterTest.java
@Before
public void setUp() throws GeneralSecurityException {
  ResourceLeakDetector.setLevel(Level.PARANOID);
  client = new AltsChannelCrypter(new byte[AltsChannelCrypter.getKeyLength()], true);
  server = new AltsChannelCrypter(new byte[AltsChannelCrypter.getKeyLength()], false);
}
 
源代码14 项目: grpc-nebula-java   文件: FakeTsiTest.java
@Before
public void setUp() {
  ResourceLeakDetector.setLevel(Level.PARANOID);
}
 
源代码15 项目: proxyee-down   文件: HttpDownSpringBoot.java
@Override
public void afterPropertiesSet() throws Exception {
  if ("dev".equalsIgnoreCase(active.trim())) {
    ResourceLeakDetector.setLevel(Level.ADVANCED);
  }
}
 
源代码16 项目: rpc-benchmark   文件: Server.java
public static void main(String[] args) throws Exception {
	ResourceLeakDetector.setLevel(Level.DISABLED);
	SpringApplication.run(Server.class, args);
}
 
源代码17 项目: riposte   文件: MainClassUtilsTest.java
private void resetNettyLeakDetectionLevel() {
    System.clearProperty(NETTY_LEAK_DETECTION_LEVEL_SYSTEM_PROP_KEY);
    ResourceLeakDetector.setLevel(Level.SIMPLE);
}
 
源代码18 项目: riposte   文件: MainClassUtilsTest.java
@DataProvider(value = {
    // no-op case
    "null       |   null        |   null        |   null",
    // cases showing that system property takes precedence over everything
    "PARANOID   |   null        |   null        |   PARANOID",
    "disabled   |   PARANOID    |   null        |   DISABLED", // also - lowercase works
    "aDvAnCeD   |   PARANOID    |   DISABLED    |   ADVANCED", // also - mixed case works
    // cases showing that NETTY_LEAK_DETECTION_LEVEL_SYSTEM_PROP_KEY takes precedence
    //      over NETTY_LEAK_DETECTION_LEVEL_APP_PROP_KEY if the system property is absent
    "null       |   ADVANCED    |   null        |   ADVANCED",
    "null       |   aDvAnCeD    |   PARANOID    |   ADVANCED", // yes, lower/mixed case still works here too
    // cases showing NETTY_LEAK_DETECTION_LEVEL_APP_PROP_KEY will be used if the other
    //      options are not available
    "null       |   null        |   DISABLED    |   DISABLED",
    "null       |   null        |   pArAnOiD    |   PARANOID", // yes, lower/mixed case still works here too
}, splitBy = "\\|")
@Test
public void setupNettyLeakDetectionLevel_works_as_expected(
    String systemPropValue, String configValueForSystemPropKey, String configValueForAppPropKey, Level expectedFinalLevel
) {
    // given
    assertThat(ResourceLeakDetector.getLevel()).isEqualTo(Level.SIMPLE);
    assertThat(expectedFinalLevel).isNotEqualTo(Level.SIMPLE);

    setSystemPropWithNullSupport(NETTY_LEAK_DETECTION_LEVEL_SYSTEM_PROP_KEY, systemPropValue);
    Function<String, String> propertyExtractionFunction = (key) -> {
        switch(key) {
            case NETTY_LEAK_DETECTION_LEVEL_SYSTEM_PROP_KEY:
                return configValueForSystemPropKey;
            case NETTY_LEAK_DETECTION_LEVEL_APP_PROP_KEY:
                return configValueForAppPropKey;
            default:
                throw new IllegalArgumentException("Unhandled config key: " + key);
        }
    };
    Function<String, Boolean> hasPropertyFunction = (key) -> (propertyExtractionFunction.apply(key) != null);

    // when
    MainClassUtils.setupNettyLeakDetectionLevel(hasPropertyFunction, propertyExtractionFunction);

    // then
    if (expectedFinalLevel == null) {
        // We expect that the method did nothing since it couldn't find anything to set
        assertThat(System.getProperty(NETTY_LEAK_DETECTION_LEVEL_SYSTEM_PROP_KEY)).isNull();
        assertThat(ResourceLeakDetector.getLevel()).isEqualTo(Level.SIMPLE);
    }
    else {
        assertThat(System.getProperty(NETTY_LEAK_DETECTION_LEVEL_SYSTEM_PROP_KEY))
            .isEqualTo(expectedFinalLevel.name());
        assertThat(ResourceLeakDetector.getLevel()).isEqualTo(expectedFinalLevel);
    }
}
 
源代码19 项目: grpc-java   文件: AltsTsiFrameProtectorTest.java
@Before
public void setUp() {
  ResourceLeakDetector.setLevel(Level.PARANOID);
}
 
源代码20 项目: grpc-java   文件: AltsChannelCrypterTest.java
@Before
public void setUp() throws GeneralSecurityException {
  ResourceLeakDetector.setLevel(Level.PARANOID);
  client = new AltsChannelCrypter(new byte[AltsChannelCrypter.getKeyLength()], true);
  server = new AltsChannelCrypter(new byte[AltsChannelCrypter.getKeyLength()], false);
}
 
源代码21 项目: grpc-java   文件: FakeTsiTest.java
@Before
public void setUp() {
  ResourceLeakDetector.setLevel(Level.PARANOID);
}
 
 类所在包
 同包方法