Search in sources :

Example 1 with EzySocketStatistics

use of com.tvd12.ezyfoxserver.statistics.EzySocketStatistics in project ezyfox-server by youngmonkeys.

the class EzySimpleStatisticsTest method test.

public void test(int max) throws Exception {
    EzySimpleStatistics statistics = new EzySimpleStatistics();
    EzySocketStatistics socketStats = statistics.getSocketStats();
    EzyNetworkStats networkStats = (EzyNetworkStats) socketStats.getNetworkStats();
    AtomicInteger count = new AtomicInteger();
    Thread[] threads = new Thread[max];
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new Thread(() -> {
            networkStats.addReadBytes(50);
            networkStats.addReadPackets(1);
            networkStats.addWrittenBytes(2 * 50);
            networkStats.addWrittenPackets(2);
            count.incrementAndGet();
        });
    }
    for (Thread thread : threads) {
        thread.start();
    }
    while (count.get() < max) {
        EzyThreads.sleep(5L);
    }
    Thread.sleep(100);
    System.out.println("getReadBytes: " + networkStats.getReadBytes());
    System.out.println("getReadPackets: " + networkStats.getReadPackets());
    System.out.println("getWrittenBytes: " + networkStats.getWrittenBytes());
    System.out.println("getWrittenPackets: " + networkStats.getWrittenPackets());
    System.out.println(networkStats.getReadBytes());
    System.out.println(networkStats.getReadPackets());
    System.out.println(networkStats.getWrittenBytes());
    System.out.println(networkStats.getWrittenPackets());
    assert statistics.getStartTime() > 0;
    assert statistics.getWebSocketStats() != null;
}
Also used : EzySocketStatistics(com.tvd12.ezyfoxserver.statistics.EzySocketStatistics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EzyNetworkStats(com.tvd12.ezyfoxserver.statistics.EzyNetworkStats) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics)

Aggregations

EzyNetworkStats (com.tvd12.ezyfoxserver.statistics.EzyNetworkStats)1 EzySimpleStatistics (com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics)1 EzySocketStatistics (com.tvd12.ezyfoxserver.statistics.EzySocketStatistics)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1