pull/32521/head
Phillip Webb 2 years ago
parent 757a0c2664
commit 4bcec6e0ee

@ -37,6 +37,8 @@ import org.springframework.boot.actuate.endpoint.jmx.annotation.JmxEndpointDisco
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ContextConsumer;
import org.springframework.context.ConfigurableApplicationContext;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -52,6 +54,9 @@ import static org.mockito.Mockito.times;
*/ */
class JmxEndpointAutoConfigurationTests { class JmxEndpointAutoConfigurationTests {
private static final ContextConsumer<ConfigurableApplicationContext> NO_OPERATION = (context) -> {
};
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EndpointAutoConfiguration.class, JmxAutoConfiguration.class, .withConfiguration(AutoConfigurations.of(EndpointAutoConfiguration.class, JmxAutoConfiguration.class,
JmxEndpointAutoConfiguration.class)) JmxEndpointAutoConfiguration.class))
@ -90,11 +95,11 @@ class JmxEndpointAutoConfigurationTests {
given(this.mBeanServer.queryNames(any(), any())) given(this.mBeanServer.queryNames(any(), any()))
.willReturn(new HashSet<>(Arrays.asList(new ObjectName("test:test=test")))); .willReturn(new HashSet<>(Arrays.asList(new ObjectName("test:test=test"))));
ArgumentCaptor<ObjectName> objectName = ArgumentCaptor.forClass(ObjectName.class); ArgumentCaptor<ObjectName> objectName = ArgumentCaptor.forClass(ObjectName.class);
this.contextRunner.withPropertyValues("spring.jmx.enabled=true").with(mockMBeanServer()).run((parent) -> { ApplicationContextRunner jmxEnabledContextRunner = this.contextRunner
this.contextRunner.withPropertyValues("spring.jmx.enabled=true").withParent(parent).run((child) -> { .withPropertyValues("spring.jmx.enabled=true");
}); jmxEnabledContextRunner.with(mockMBeanServer()).run((parent) -> {
this.contextRunner.withPropertyValues("spring.jmx.enabled=true").withParent(parent).run((child) -> { jmxEnabledContextRunner.withParent(parent).run(NO_OPERATION);
}); jmxEnabledContextRunner.withParent(parent).run(NO_OPERATION);
}); });
then(this.mBeanServer).should(times(3)).registerMBean(any(Object.class), objectName.capture()); then(this.mBeanServer).should(times(3)).registerMBean(any(Object.class), objectName.capture());
Set<ObjectName> uniqueValues = new HashSet<>(objectName.getAllValues()); Set<ObjectName> uniqueValues = new HashSet<>(objectName.getAllValues());

@ -61,12 +61,8 @@ final class ImageBuildpack implements Buildpack {
Image image = context.fetchImage(reference, ImageType.BUILDPACK); Image image = context.fetchImage(reference, ImageType.BUILDPACK);
BuildpackMetadata buildpackMetadata = BuildpackMetadata.fromImage(image); BuildpackMetadata buildpackMetadata = BuildpackMetadata.fromImage(image);
this.coordinates = BuildpackCoordinates.fromBuildpackMetadata(buildpackMetadata); this.coordinates = BuildpackCoordinates.fromBuildpackMetadata(buildpackMetadata);
if (!buildpackExistsInBuilder(context, image.getLayers())) { this.exportedLayers = (!buildpackExistsInBuilder(context, image.getLayers()))
this.exportedLayers = new ExportedLayers(context, reference); ? new ExportedLayers(context, reference) : null;
}
else {
this.exportedLayers = null;
}
} }
catch (IOException | DockerEngineException ex) { catch (IOException | DockerEngineException ex) {
throw new IllegalArgumentException("Error pulling buildpack image '" + reference + "'", ex); throw new IllegalArgumentException("Error pulling buildpack image '" + reference + "'", ex);
@ -76,11 +72,8 @@ final class ImageBuildpack implements Buildpack {
private boolean buildpackExistsInBuilder(BuildpackResolverContext context, List<LayerId> imageLayers) { private boolean buildpackExistsInBuilder(BuildpackResolverContext context, List<LayerId> imageLayers) {
BuildpackLayerDetails buildpackLayerDetails = context.getBuildpackLayersMetadata() BuildpackLayerDetails buildpackLayerDetails = context.getBuildpackLayersMetadata()
.getBuildpack(this.coordinates.getId(), this.coordinates.getVersion()); .getBuildpack(this.coordinates.getId(), this.coordinates.getVersion());
if (buildpackLayerDetails != null) { String layerDiffId = (buildpackLayerDetails != null) ? buildpackLayerDetails.getLayerDiffId() : null;
String layerDiffId = buildpackLayerDetails.getLayerDiffId(); return (layerDiffId != null) && imageLayers.stream().map(LayerId::toString).anyMatch(layerDiffId::equals);
return imageLayers.stream().map(LayerId::toString).anyMatch((layerId) -> layerId.equals(layerDiffId));
}
return false;
} }
@Override @Override

Loading…
Cancel
Save