11/*
2- * Copyright (c) 2000, 2024 , Oracle and/or its affiliates.
2+ * Copyright (c) 2000, 2025 , Oracle and/or its affiliates.
33 *
44 * Licensed under the Universal Permissive License v 1.0 as shown at
55 * https://oss.oracle.com/licenses/upl.
2525import com .oracle .bedrock .runtime .options .StabilityPredicate ;
2626import com .oracle .bedrock .testsupport .deferred .Eventually ;
2727
28- import com .tangosol .internal .net .metrics .MetricsHttpHelper ;
28+ import com .tangosol .discovery .NSLookup ;
29+
2930import com .tangosol .net .Coherence ;
3031
3132import executor .common .CoherenceClusterResource ;
3233import executor .common .LogOutput ;
3334import executor .common .SingleClusterForAllTests ;
3435import executor .common .Utils ;
3536
37+ import java .net .InetSocketAddress ;
38+ import java .net .URL ;
39+
3640import metrics .AbstractMetricsFunctionalTest ;
3741
3842import java .util .LinkedHashMap ;
3943import java .util .Map ;
4044
41- import org .hamcrest .CoreMatchers ;
42-
4345import org .junit .BeforeClass ;
4446import org .junit .ClassRule ;
4547import org .junit .Test ;
48+
4649import org .junit .experimental .categories .Category ;
4750
48- import static com . oracle . bedrock . deferred . DeferredHelper . invoking ;
49- import static org . hamcrest . Matchers . greaterThan ;
51+ import static org . hamcrest . CoreMatchers . is ;
52+
5053import static org .junit .Assert .fail ;
5154
5255
@@ -97,18 +100,35 @@ public String getLabel()
97100 public void shouldUseDefaultExecutor ()
98101 {
99102 Utils .assertWithFailureAction (super ::shouldUseDefaultExecutor , this ::dumpExecutorCacheStates );
103+ Utils .assertWithFailureAction (this ::validateMetrics , this ::dumpExecutorCacheStates );
104+ }
105+
106+ // ----- helper methods -------------------------------------------------
100107
108+ protected void validateMetrics ()
109+ {
110+ Eventually .assertDeferred (this ::getCompletedMetricsAggregate , is (23L ));
111+ }
112+
113+ protected long getCompletedMetricsAggregate ()
114+ {
101115 AbstractMetricsFunctionalTest metricsHelper = new AbstractMetricsFunctionalTest ();
102116 Map <String , String > tags = new LinkedHashMap <>();
117+ long clInvoked = 0 ;
103118
104119 try
105120 {
106- Eventually .assertThat (invoking (metricsHelper ).getCacheMetric (s_metrics_port , "Coherence.Executor.TasksCompletedCount" , tags ), CoreMatchers .is (greaterThan (4L )));
121+ for (URL url : NSLookup .lookupHTTPMetricsURL (new InetSocketAddress ("127.0.0.1" , 7778 )))
122+ {
123+ clInvoked += metricsHelper .getCacheMetric (url .getPort (), TASK_COMP_COUNT_METRIC , tags );
124+ }
107125 }
108126 catch (Exception e )
109127 {
110128 fail ("Get Executor metrics failed with exception: " + e );
111129 }
130+
131+ return clInvoked ;
112132 }
113133
114134 // ----- constants ------------------------------------------------------
@@ -117,7 +137,9 @@ public void shouldUseDefaultExecutor()
117137
118138 protected static final String METRICS_ENABLED_PROPERTY = "coherence.metrics.http.enabled" ;
119139
120- protected static int s_metrics_port = MetricsHttpHelper .DEFAULT_PROMETHEUS_METRICS_PORT ;
140+ protected static final String METRICS_PORT_PROPERTY = "coherence.metrics.http.port" ;
141+
142+ protected static final String TASK_COMP_COUNT_METRIC = "Coherence.Executor.TasksCompletedCount" ;
121143
122144 // ----- data members ---------------------------------------------------
123145
@@ -136,6 +158,7 @@ public void shouldUseDefaultExecutor()
136158 ClusterName .of (CESJavaSingleClusterTests .class .getSimpleName ()), // default name is too long
137159 SystemProperty .of (EXTEND_ADDRESS_PROPERTY , EXTEND_HOST ),
138160 SystemProperty .of (EXTEND_PORT_PROPERTY , EXTEND_PORT ),
161+ SystemProperty .of (METRICS_PORT_PROPERTY , "0" ),
139162 JmxFeature .enabled (),
140163 StabilityPredicate .of (CoherenceCluster .Predicates .isCoherenceRunning ()))
141164 .include (STORAGE_ENABLED_MEMBER_COUNT ,
@@ -144,21 +167,23 @@ public void shouldUseDefaultExecutor()
144167 RoleName .of (STORAGE_ENABLED_MEMBER_ROLE ),
145168 LocalStorage .enabled (),
146169 SystemProperty .of (EXTEND_ENABLED_PROPERTY , false ),
170+ SystemProperty .of (METRICS_ENABLED_PROPERTY , true ),
147171 SystemProperty .of (EXECUTOR_LOGGING_PROPERTY , true ))
148172 .include (STORAGE_DISABLED_MEMBER_COUNT ,
149173 DisplayName .of ("ComputeServer" ),
150174 LogOutput .to (CESJavaSingleClusterTests .class .getSimpleName (), "ComputeServer" ),
151175 RoleName .of (STORAGE_DISABLED_MEMBER_ROLE ),
152176 LocalStorage .disabled (),
153- SystemProperty .of (METRICS_ENABLED_PROPERTY , true ),
154177 SystemProperty .of (EXTEND_ENABLED_PROPERTY , false ),
178+ SystemProperty .of (METRICS_ENABLED_PROPERTY , true ),
155179 SystemProperty .of (EXECUTOR_LOGGING_PROPERTY , true ))
156180 .include (PROXY_MEMBER_COUNT ,
157181 DisplayName .of ("ProxyServer" ),
158182 LogOutput .to (CESJavaSingleClusterTests .class .getSimpleName (), "ProxyServer" ),
159183 RoleName .of (PROXY_MEMBER_ROLE ),
160184 LocalStorage .disabled (),
161185 SystemProperty .of (EXTEND_ENABLED_PROPERTY , true ),
186+ SystemProperty .of (METRICS_ENABLED_PROPERTY , true ),
162187 SystemProperty .of (EXECUTOR_LOGGING_PROPERTY , true ));
163188 }
164189
0 commit comments