|
| 1 | +// Copyright 2022 The NATS Authors |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at: |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | +package nats.io; |
| 14 | + |
| 15 | +import org.junit.jupiter.api.Test; |
| 16 | + |
| 17 | +import java.io.IOException; |
| 18 | +import java.util.logging.Level; |
| 19 | + |
| 20 | +public class DisplayLevelTest extends TestBase { |
| 21 | + |
| 22 | + // RUN THIS TEST MANUALLY TO SEE THE PROPER SERVER OUTPUT |
| 23 | + @Test |
| 24 | + public void testDisplayOutLevel() throws IOException, InterruptedException { |
| 25 | + System.out.println("------------------------------------------------------------------------------"); |
| 26 | + System.out.println("THIS SHOULD SHOW EVERYTHING. Level:ALL (Default), No Error."); |
| 27 | + System.out.println("------------------------------------------------------------------------------"); |
| 28 | + try (NatsServerRunner runner = NatsServerRunner.builder() |
| 29 | + .build()) |
| 30 | + { |
| 31 | + connect(runner); |
| 32 | + } |
| 33 | + catch (Exception ignore) {} |
| 34 | + |
| 35 | + System.out.println("------------------------------------------------------------------------------"); |
| 36 | + System.out.println("THIS SHOULD ALSO SHOW EVERYTHING. Level:INFO, No Error."); |
| 37 | + System.out.println("------------------------------------------------------------------------------"); |
| 38 | + try (NatsServerRunner runner = NatsServerRunner.builder() |
| 39 | + .displayOutLevel(Level.INFO) |
| 40 | + .build()) |
| 41 | + { |
| 42 | + connect(runner); |
| 43 | + } |
| 44 | + catch (Exception ignore) {} |
| 45 | + |
| 46 | + Thread.sleep(100); |
| 47 | + System.out.println("------------------------------------------------------------------------------"); |
| 48 | + System.out.println("THIS SHOULD SHOW THE ERROR ONLY. Level:SEVERE, Yes Error."); |
| 49 | + System.out.println("------------------------------------------------------------------------------"); |
| 50 | + try (NatsServerRunner runner = NatsServerRunner.builder() |
| 51 | + .configFilePath("not-a-real-path") |
| 52 | + .displayOutLevel(Level.SEVERE) |
| 53 | + .build()) |
| 54 | + { |
| 55 | + connect(runner); |
| 56 | + } |
| 57 | + catch (Exception ignore) {} |
| 58 | + |
| 59 | + Thread.sleep(100); |
| 60 | + System.out.println("------------------------------------------------------------------------------"); |
| 61 | + System.out.println("THIS SHOULD ALSO SHOW THE ERROR ONLY. Level:INFO, Yes Error."); |
| 62 | + System.out.println("------------------------------------------------------------------------------"); |
| 63 | + try (NatsServerRunner runner = NatsServerRunner.builder() |
| 64 | + .configFilePath("not-a-real-path") |
| 65 | + .displayOutLevel(Level.INFO) |
| 66 | + .build()) |
| 67 | + { |
| 68 | + connect(runner); |
| 69 | + } |
| 70 | + catch (Exception ignore) {} |
| 71 | + |
| 72 | + Thread.sleep(100); |
| 73 | + System.out.println("------------------------------------------------------------------------------"); |
| 74 | + System.out.println("THIS SHOULD SHOW NOTHING. Level:OFF, Yes Error."); |
| 75 | + System.out.println("------------------------------------------------------------------------------"); |
| 76 | + try (NatsServerRunner runner = NatsServerRunner.builder() |
| 77 | + .configFilePath("not-a-real-path") |
| 78 | + .displayOutLevel(Level.OFF) |
| 79 | + .build()) |
| 80 | + { |
| 81 | + connect(runner); |
| 82 | + } |
| 83 | + catch (Exception ignore) {} |
| 84 | + |
| 85 | + Thread.sleep(100); |
| 86 | + System.out.println("------------------------------------------------------------------------------"); |
| 87 | + System.out.println("THIS SHOULD ALSO SHOW NOTHING. Level:SEVERE, No Error."); |
| 88 | + System.out.println("------------------------------------------------------------------------------"); |
| 89 | + try (NatsServerRunner runner = NatsServerRunner.builder() |
| 90 | + .displayOutLevel(Level.SEVERE) |
| 91 | + .build()) |
| 92 | + { |
| 93 | + connect(runner); |
| 94 | + } |
| 95 | + catch (Exception ignore) {} |
| 96 | + |
| 97 | + System.out.println("------------------------------------------------------------------------------"); |
| 98 | + } |
| 99 | +} |
0 commit comments