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 ;
@@ -233,6 +235,11 @@ private void commonInit() {
233235 }
234236 if (isHollow ) {
235237 setContainerIpAddress (ManuallyStartedConfiguration .getHostname ());
238+ try {
239+ setFirstMappedPort (new URL (ManuallyStartedConfiguration .getRuntimeURL ()).getPort ());
240+ } catch (MalformedURLException e ) {
241+ LOG .debug ("Unable to obtain port from " + ManuallyStartedConfiguration .getRuntimeURL (), e );
242+ }
236243 withAppContextRoot (ManuallyStartedConfiguration .getBasePath ());
237244 } else {
238245 withAppContextRoot ("/" );
@@ -273,6 +280,10 @@ public void setFirstMappedPort(int port) {
273280 if (!isHollow )
274281 throw new IllegalStateException ("Can only set first mapped port in hollow mode" );
275282 primaryPort = port ;
283+ List <Integer > exposedPorts = new ArrayList <>(getExposedPorts ());
284+ if (!exposedPorts .contains (primaryPort ))
285+ exposedPorts .add (0 , primaryPort );
286+ setExposedPorts (exposedPorts );
276287 }
277288
278289 @ Override
You can’t perform that action at this time.
0 commit comments