Skip to content

Commit

Permalink
Add forwarding adapter test to Java Metrics test (#2352)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Jun 26, 2024
1 parent d687471 commit e737707
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
8 changes: 7 additions & 1 deletion java/test/src/main/java/test/Ice/metrics/AMDServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ public void run(String[] args) {
adapter.add(new AMDMetricsI(), com.zeroc.Ice.Util.stringToIdentity("metrics"));
adapter.activate();

communicator.getProperties().setProperty("ControllerAdapter.Endpoints", getTestEndpoint(1));
communicator.getProperties().setProperty("ForwardingAdapter.Endpoints", getTestEndpoint(1));
com.zeroc.Ice.ObjectAdapter forwardingAdapter =
communicator.createObjectAdapter("ForwardingAdapter");
forwardingAdapter.addDefaultServant(adapter.dispatchPipeline(), "");
forwardingAdapter.activate();

communicator.getProperties().setProperty("ControllerAdapter.Endpoints", getTestEndpoint(2));
com.zeroc.Ice.ObjectAdapter controllerAdapter =
communicator.createObjectAdapter("ControllerAdapter");
controllerAdapter.add(
Expand Down
24 changes: 19 additions & 5 deletions java/test/src/main/java/test/Ice/metrics/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ private static void test(boolean b) {
}
}

static String getPort(com.zeroc.Ice.PropertiesAdminPrx p) {
static String getPort(com.zeroc.Ice.PropertiesAdminPrx p, int testPort) {
return Integer.toString(
test.TestHelper.getTestPort(p.ice_getCommunicator().getProperties(), 0));
test.TestHelper.getTestPort(p.ice_getCommunicator().getProperties(), testPort));
}

static ConnectionMetrics getServerConnectionMetrics(MetricsAdminPrx metrics, long expected) {
Expand Down Expand Up @@ -98,7 +98,7 @@ private static Map<String, String> getClientProps(
map += "Map." + m + '.';
}
props.put("IceMX.Metrics.View." + map + "Reject.parent", "Ice\\.Admin");
props.put("IceMX.Metrics.View." + map + "Accept.endpointPort", getPort(p));
props.put("IceMX.Metrics.View." + map + "Accept.endpointPort", getPort(p, 0));
props.put("IceMX.Metrics.View." + map + "Reject.identity", ".*/admin|controller");
return props;
}
Expand All @@ -117,7 +117,9 @@ private static Map<String, String> getServerProps(
map += "Map." + m + '.';
}
props.put("IceMX.Metrics.View." + map + "Reject.parent", "Ice\\.Admin|Controller");
props.put("IceMX.Metrics.View." + map + "Accept.endpointPort", getPort(p));
// Regular expression to match server test endpoint 0 and test endpoint 1
props.put(
"IceMX.Metrics.View." + map + "Accept.endpointPort", getPort(p, 0) + "|" + getPort(p, 1));
return props;
}

Expand Down Expand Up @@ -312,6 +314,8 @@ static MetricsPrx allTests(test.TestHelper helper, CommunicatorObserverI obsv)
String hostAndPort = host + ":" + port;
String protocol = helper.getTestProtocol();
String endpoint = protocol + " -h " + host + " -p " + port;
String forwardingEndpoint =
protocol + " -h " + host + " -p " + Integer.toString(helper.getTestPort(1));

MetricsPrx metrics = MetricsPrx.checkedCast(communicator.stringToProxy("metrics:" + endpoint));
boolean collocated = metrics.ice_getConnection() == null;
Expand Down Expand Up @@ -514,7 +518,7 @@ static MetricsPrx allTests(test.TestHelper helper, CommunicatorObserverI obsv)

ControllerPrx controller =
ControllerPrx.checkedCast(
communicator.stringToProxy("controller:" + helper.getTestEndpoint(1)));
communicator.stringToProxy("controller:" + helper.getTestEndpoint(2)));
controller.hold();

map = toMap(clientMetrics.getMetricsView("View").returnValue.get("Connection"));
Expand Down Expand Up @@ -845,6 +849,16 @@ static MetricsPrx allTests(test.TestHelper helper, CommunicatorObserverI obsv)

out.println("ok");

out.print("testing dispatch metrics with forwarding object adapter... ");
out.flush();
MetricsPrx indirectMetrics =
MetricsPrx.createProxy(communicator, "metrics:" + forwardingEndpoint);
var secondOp = new InvokeOp(indirectMetrics);
testAttribute(
serverMetrics, serverProps, "Dispatch", "parent", "ForwardingAdapter", secondOp, out);
testAttribute(serverMetrics, serverProps, "Dispatch", "id", "metrics [op]", secondOp, out);
out.println("ok");

out.print("testing invocation metrics... ");
out.flush();

Expand Down
7 changes: 6 additions & 1 deletion java/test/src/main/java/test/Ice/metrics/Collocated.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public void run(String[] args) {
adapter.add(new MetricsI(), com.zeroc.Ice.Util.stringToIdentity("metrics"));
// adapter.activate(); // Don't activate OA to ensure collocation is used.

communicator.getProperties().setProperty("ControllerAdapter.Endpoints", getTestEndpoint(1));
communicator.getProperties().setProperty("ForwardingAdapter.Endpoints", getTestEndpoint(1));
com.zeroc.Ice.ObjectAdapter forwardingAdapter =
communicator.createObjectAdapter("ForwardingAdapter");
forwardingAdapter.addDefaultServant(adapter.dispatchPipeline(), "");

communicator.getProperties().setProperty("ControllerAdapter.Endpoints", getTestEndpoint(2));
com.zeroc.Ice.ObjectAdapter controllerAdapter =
communicator.createObjectAdapter("ControllerAdapter");
controllerAdapter.add(
Expand Down
8 changes: 7 additions & 1 deletion java/test/src/main/java/test/Ice/metrics/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ public void run(String[] args) {
adapter.add(new MetricsI(), com.zeroc.Ice.Util.stringToIdentity("metrics"));
adapter.activate();

communicator.getProperties().setProperty("ControllerAdapter.Endpoints", getTestEndpoint(1));
communicator.getProperties().setProperty("ForwardingAdapter.Endpoints", getTestEndpoint(1));
com.zeroc.Ice.ObjectAdapter forwardingAdapter =
communicator.createObjectAdapter("ForwardingAdapter");
forwardingAdapter.addDefaultServant(adapter.dispatchPipeline(), "");
forwardingAdapter.activate();

communicator.getProperties().setProperty("ControllerAdapter.Endpoints", getTestEndpoint(2));
com.zeroc.Ice.ObjectAdapter controllerAdapter =
communicator.createObjectAdapter("ControllerAdapter");
controllerAdapter.add(
Expand Down

0 comments on commit e737707

Please sign in to comment.