Search in sources :

Example 1 with SettableSupplier

use of org.opensearch.ml.stats.suppliers.SettableSupplier in project ml-commons by opensearch-project.

the class MLStatsNodesTransportActionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    clusterStatName1 = "clusterStat1";
    nodeStatName1 = "nodeStat1";
    statsMap = new HashMap<String, MLStat<?>>() {

        {
            put(nodeStatName1, new MLStat<>(false, new CounterSupplier()));
            put(clusterStatName1, new MLStat<>(true, new CounterSupplier()));
            put(InternalStatNames.JVM_HEAP_USAGE.getName(), new MLStat<>(true, new SettableSupplier()));
        }
    };
    mlStats = new MLStats(statsMap);
    Environment environment = mock(Environment.class);
    Settings settings = Settings.builder().build();
    when(environment.settings()).thenReturn(settings);
    action = new MLStatsNodesTransportAction(client().threadPool(), clusterService(), mock(TransportService.class), mock(ActionFilters.class), mlStats, environment);
}
Also used : CounterSupplier(org.opensearch.ml.stats.suppliers.CounterSupplier) SettableSupplier(org.opensearch.ml.stats.suppliers.SettableSupplier) MLStats(org.opensearch.ml.stats.MLStats) MLStat(org.opensearch.ml.stats.MLStat) Environment(org.opensearch.env.Environment) Settings(org.opensearch.common.settings.Settings) Before(org.junit.Before)

Example 2 with SettableSupplier

use of org.opensearch.ml.stats.suppliers.SettableSupplier in project ml-commons by opensearch-project.

the class MLStatTests method testSetGetValue.

public void testSetGetValue() {
    MLStat<Long> stat1 = new MLStat<>(false, new CounterSupplier());
    Assert.assertEquals("GetValue returns the incorrect value", 0L, (long) (stat1.getValue()));
    stat1.setValue(1L);
    Assert.assertEquals("GetValue returns the incorrect value", 0L, (long) (stat1.getValue()));
    MLStat<String> stat2 = new MLStat<>(false, new TestSupplier());
    Assert.assertEquals("GetValue returns the incorrect value", "test", stat2.getValue());
    stat2.setValue(1L);
    Assert.assertEquals("GetValue returns the incorrect value", "test", stat2.getValue());
    MLStat<Long> stat3 = new MLStat<>(false, new SettableSupplier());
    Assert.assertEquals("GetValue returns the incorrect value", 0L, (long) stat3.getValue());
    stat3.setValue(1L);
    Assert.assertEquals("GetValue returns the incorrect value", 1L, (long) stat3.getValue());
}
Also used : CounterSupplier(org.opensearch.ml.stats.suppliers.CounterSupplier) SettableSupplier(org.opensearch.ml.stats.suppliers.SettableSupplier)

Aggregations

CounterSupplier (org.opensearch.ml.stats.suppliers.CounterSupplier)2 SettableSupplier (org.opensearch.ml.stats.suppliers.SettableSupplier)2 Before (org.junit.Before)1 Settings (org.opensearch.common.settings.Settings)1 Environment (org.opensearch.env.Environment)1 MLStat (org.opensearch.ml.stats.MLStat)1 MLStats (org.opensearch.ml.stats.MLStats)1