File tree Expand file tree Collapse file tree
modules/testcontainers/src/main/java/org/microshed/testing/testcontainers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323import java .lang .annotation .Annotation ;
2424import java .lang .reflect .InvocationTargetException ;
2525import java .lang .reflect .Method ;
26+ import java .net .MalformedURLException ;
2627import java .net .URI ;
28+ import java .net .URL ;
2729import java .nio .file .Files ;
2830import java .nio .file .Path ;
2931import java .nio .file .Paths ;
@@ -230,6 +232,11 @@ private void commonInit() {
230232 }
231233 if (isHollow ) {
232234 setContainerIpAddress (ManuallyStartedConfiguration .getHostname ());
235+ try {
236+ setFirstMappedPort (new URL (ManuallyStartedConfiguration .getRuntimeURL ()).getPort ());
237+ } catch (MalformedURLException e ) {
238+ LOG .debug ("Unable to obtain port from " + ManuallyStartedConfiguration .getRuntimeURL (), e );
239+ }
233240 withAppContextRoot (ManuallyStartedConfiguration .getBasePath ());
234241 } else {
235242 withAppContextRoot ("/" );
@@ -270,6 +277,10 @@ public void setFirstMappedPort(int port) {
270277 if (!isHollow )
271278 throw new IllegalStateException ("Can only set first mapped port in hollow mode" );
272279 primaryPort = port ;
280+ List <Integer > exposedPorts = new ArrayList <>(getExposedPorts ());
281+ if (!exposedPorts .contains (primaryPort ))
282+ exposedPorts .add (0 , primaryPort );
283+ setExposedPorts (exposedPorts );
273284 }
274285
275286 @ Override
You can’t perform that action at this time.
0 commit comments