1919import com .squareup .okhttp .OkHttpClient ;
2020import org .graylog .plugins .usagestatistics .providers .SmileObjectMapperProvider ;
2121import org .graylog2 .plugin .ServerStatus ;
22- import org .graylog2 .plugin .cluster .ClusterConfigService ;
2322import org .graylog2 .plugin .cluster .ClusterId ;
2423import org .graylog2 .plugin .system .NodeId ;
2524import org .junit .Before ;
@@ -42,17 +41,18 @@ public class UsageStatsNodePeriodicalTest {
4241 private ServerStatus serverStatus ;
4342 private UsageStatsConfiguration configuration ;
4443 @ Mock
45- private ClusterConfigService clusterConfigService ;
46- @ Mock
4744 private OkHttpClient httpClient ;
45+
46+ private TestClusterConfigService clusterConfigService ;
4847 private ObjectMapper objectMapper ;
4948 private UsageStatsNodePeriodical periodical ;
5049
5150 @ Before
5251 public void setUp () throws Exception {
5352 when (nodeId .anonymize ()).thenReturn ("test-node-id" );
5453 configuration = spy (new UsageStatsConfiguration ());
55- when (clusterConfigService .get (ClusterId .class )).thenReturn (ClusterId .create ("test-cluster-id" ));
54+
55+ clusterConfigService = new TestClusterConfigService ();
5656 objectMapper = new SmileObjectMapperProvider ().get ();
5757 periodical = new UsageStatsNodePeriodical (
5858 nodeService ,
@@ -63,6 +63,8 @@ public void setUp() throws Exception {
6363 httpClient ,
6464 objectMapper
6565 );
66+
67+ clusterConfigService .write (ClusterId .create ("test-cluster-id" ));
6668 }
6769
6870 @ Test
@@ -93,27 +95,27 @@ public void testStartOnThisNode() throws Exception {
9395 @ Test
9496 public void testIsEnabled () throws Exception {
9597 when (configuration .isEnabled ()).thenReturn (true );
96- when ( clusterConfigService .get ( UsageStatsOptOutState .class )). thenReturn ( null );
98+ clusterConfigService .remove ( AutoValue_UsageStatsOptOutState .class );
9799 assertThat (periodical .isEnabled ()).isTrue ();
98100
99101 when (configuration .isEnabled ()).thenReturn (true );
100- when ( clusterConfigService .get ( UsageStatsOptOutState . class )). thenReturn (UsageStatsOptOutState .create (false ));
102+ clusterConfigService .write (UsageStatsOptOutState .create (false ));
101103 assertThat (periodical .isEnabled ()).isTrue ();
102104
103105 when (configuration .isEnabled ()).thenReturn (false );
104- when ( clusterConfigService .get ( UsageStatsOptOutState .class )). thenReturn ( null );
106+ clusterConfigService .remove ( AutoValue_UsageStatsOptOutState .class );
105107 assertThat (periodical .isEnabled ()).isFalse ();
106108
107109 when (configuration .isEnabled ()).thenReturn (false );
108- when ( clusterConfigService .get ( UsageStatsOptOutState . class )). thenReturn (UsageStatsOptOutState .create (false ));
110+ clusterConfigService .write (UsageStatsOptOutState .create (false ));
109111 assertThat (periodical .isEnabled ()).isFalse ();
110112
111113 when (configuration .isEnabled ()).thenReturn (true );
112- when ( clusterConfigService .get ( UsageStatsOptOutState . class )). thenReturn (UsageStatsOptOutState .create (true ));
114+ clusterConfigService .write (UsageStatsOptOutState .create (true ));
113115 assertThat (periodical .isEnabled ()).isFalse ();
114116
115117 when (configuration .isEnabled ()).thenReturn (false );
116- when ( clusterConfigService .get ( UsageStatsOptOutState . class )). thenReturn (UsageStatsOptOutState .create (true ));
118+ clusterConfigService .write (UsageStatsOptOutState .create (true ));
117119 assertThat (periodical .isEnabled ()).isFalse ();
118120 }
119121}
0 commit comments