1 // Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 
6 package org.rocksdb;
7 
8 import java.util.Collections;
9 
10 import org.junit.ClassRule;
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.junit.rules.TemporaryFolder;
14 
15 import static org.assertj.core.api.Assertions.assertThat;
16 
17 public class StatisticsCollectorTest {
18 
19   @ClassRule
20   public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE =
21       new RocksNativeLibraryResource();
22 
23   @Rule
24   public TemporaryFolder dbFolder = new TemporaryFolder();
25 
26   @Test
statisticsCollector()27   public void statisticsCollector()
28       throws InterruptedException, RocksDBException {
29     try (final Statistics statistics = new Statistics();
30             final Options opt = new Options()
31         .setStatistics(statistics)
32         .setCreateIfMissing(true);
33          final RocksDB db = RocksDB.open(opt,
34              dbFolder.getRoot().getAbsolutePath())) {
35 
36       try(final Statistics stats = opt.statistics()) {
37 
38         final StatsCallbackMock callback = new StatsCallbackMock();
39         final StatsCollectorInput statsInput =
40                 new StatsCollectorInput(stats, callback);
41 
42         final StatisticsCollector statsCollector = new StatisticsCollector(
43                 Collections.singletonList(statsInput), 100);
44         statsCollector.start();
45 
46         Thread.sleep(1000);
47 
48         assertThat(callback.tickerCallbackCount).isGreaterThan(0);
49         assertThat(callback.histCallbackCount).isGreaterThan(0);
50 
51         statsCollector.shutDown(1000);
52       }
53     }
54   }
55 }
56