use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method testFailedBuild.
@Test(expected = Fabric8ServiceException.class)
public void testFailedBuild() throws Exception {
BuildService.BuildServiceConfig config = defaultConfig.build();
WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, false, 50, false, false);
OpenShiftMockServer mockServer = collector.getMockServer();
OpenShiftClient client = mockServer.createOpenShiftClient();
OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
service.build(image);
}
use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method testSuccessfulSecondBuild.
@Test
public void testSuccessfulSecondBuild() throws Exception {
int nTries = 0;
boolean bTestComplete = false;
do {
try {
nTries++;
BuildService.BuildServiceConfig config = defaultConfig.build();
WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, true, true);
OpenShiftMockServer mockServer = collector.getMockServer();
OpenShiftClient client = mockServer.createOpenShiftClient();
OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
service.build(image);
assertTrue(mockServer.getRequestCount() > 8);
collector.assertEventsRecordedInOrder("build-config-check", "patch-build-config", "pushed");
collector.assertEventsNotRecorded("new-build-config");
bTestComplete = true;
} catch (Fabric8ServiceException exception) {
Throwable rootCause = getRootCause(exception);
logger.warn("A problem encountered while running test {}, retrying..", exception.getMessage());
// Let's wait for a while, and then retry again
if (rootCause != null && rootCause instanceof IOException) {
continue;
}
}
} while (nTries < MAX_TIMEOUT_RETRIES && !bTestComplete);
}
use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method createMockServer.
protected WebServerEventCollector<OpenShiftMockServer> createMockServer(BuildService.BuildServiceConfig config, boolean success, long buildDelay, boolean buildConfigExists, boolean imageStreamExists) {
OpenShiftMockServer mockServer = new OpenShiftMockServer(false);
WebServerEventCollector<OpenShiftMockServer> collector = new WebServerEventCollector<>(mockServer);
BuildConfig bc = new BuildConfigBuilder().withNewMetadata().withName(projectName + config.getS2iBuildNameSuffix()).endMetadata().withNewSpec().endSpec().build();
ImageStream imageStream = new ImageStreamBuilder().withNewMetadata().withName(projectName).endMetadata().withStatus(new ImageStreamStatusBuilder().addNewTagLike(new NamedTagEventListBuilder().addNewItem().withImage("abcdef0123456789").endItem().build()).endTag().build()).build();
KubernetesList builds = new KubernetesListBuilder().withItems(new BuildBuilder().withNewMetadata().withName(projectName).endMetadata().build()).withNewMetadata().withResourceVersion("1").endMetadata().build();
String buildStatus = success ? "Complete" : "Fail";
Build build = new BuildBuilder().withNewMetadata().withResourceVersion("2").endMetadata().withNewStatus().withPhase(buildStatus).endStatus().build();
if (!buildConfigExists) {
mockServer.expect().get().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix()).andReply(collector.record("build-config-check").andReturn(404, "")).once();
mockServer.expect().post().withPath("/oapi/v1/namespaces/test/buildconfigs").andReply(collector.record("new-build-config").andReturn(201, bc)).once();
} else {
mockServer.expect().patch().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix()).andReply(collector.record("patch-build-config").andReturn(200, bc)).once();
}
mockServer.expect().get().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix()).andReply(collector.record("build-config-check").andReturn(200, bc)).always();
if (!imageStreamExists) {
mockServer.expect().get().withPath("/oapi/v1/namespaces/test/imagestreams/" + projectName).andReturn(404, "").once();
}
mockServer.expect().get().withPath("/oapi/v1/namespaces/test/imagestreams/" + projectName).andReturn(200, imageStream).always();
mockServer.expect().post().withPath("/oapi/v1/namespaces/test/imagestreams").andReturn(201, imageStream).once();
mockServer.expect().post().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix() + "/instantiatebinary?commit=").andReply(collector.record("pushed").andReturn(201, imageStream)).once();
mockServer.expect().get().withPath("/oapi/v1/namespaces/test/builds").andReply(collector.record("check-build").andReturn(200, builds)).always();
mockServer.expect().get().withPath("/oapi/v1/namespaces/test/builds?labelSelector=openshift.io/build-config.name%3D" + projectName + config.getS2iBuildNameSuffix()).andReturn(200, builds).always();
mockServer.expect().withPath("/oapi/v1/namespaces/test/builds/" + projectName).andReturn(200, build).always();
mockServer.expect().withPath("/oapi/v1/namespaces/test/builds?fieldSelector=metadata.name%3D" + projectName + "&watch=true").andUpgradeToWebSocket().open().waitFor(buildDelay).andEmit(new WatchEvent(build, "MODIFIED")).done().always();
return collector;
}
use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.
the class AbstractSpringBootHealthCheckEnricherSupport method testCustomPropertiesForLivenessAndReadiness.
@Test
public void testCustomPropertiesForLivenessAndReadiness() {
Map<String, TreeMap> globalConfig = new HashMap<>();
TreeMap<String, String> enricherConfig = new TreeMap<>();
globalConfig.put(SpringBootHealthCheckEnricher.ENRICHER_NAME, enricherConfig);
enricherConfig.put("readinessProbeInitialDelaySeconds", "30");
enricherConfig.put("readinessProbePeriodSeconds", "40");
enricherConfig.put("livenessProbeInitialDelaySeconds", "460");
enricherConfig.put("livenessProbePeriodSeconds", "50");
final ProcessorConfig config = new ProcessorConfig(null, null, globalConfig);
new Expectations() {
{
context.getConfig();
result = config;
}
};
withAllRequiredClasses();
withProjectProperties(new Properties());
SpringBootHealthCheckEnricher enricher = new SpringBootHealthCheckEnricher(context);
Probe probe = enricher.getReadinessProbe();
assertNotNull(probe);
assertEquals(30, probe.getInitialDelaySeconds().intValue());
assertEquals(40, probe.getPeriodSeconds().intValue());
probe = enricher.getLivenessProbe();
assertNotNull(probe);
assertEquals(460, probe.getInitialDelaySeconds().intValue());
assertEquals(50, probe.getPeriodSeconds().intValue());
}
use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.
the class AbstractSpringBootHealthCheckEnricherSupport method testCustomInitialDelayForLivenessAndReadiness.
@Test
public void testCustomInitialDelayForLivenessAndReadiness() {
Map<String, TreeMap> globalConfig = new HashMap<>();
TreeMap<String, String> enricherConfig = new TreeMap<>();
globalConfig.put(SpringBootHealthCheckEnricher.ENRICHER_NAME, enricherConfig);
enricherConfig.put("readinessProbeInitialDelaySeconds", "20");
enricherConfig.put("livenessProbeInitialDelaySeconds", "360");
final ProcessorConfig config = new ProcessorConfig(null, null, globalConfig);
new Expectations() {
{
context.getConfig();
result = config;
}
};
withAllRequiredClasses();
withProjectProperties(new Properties());
SpringBootHealthCheckEnricher enricher = new SpringBootHealthCheckEnricher(context);
Probe probe = enricher.getReadinessProbe();
assertNotNull(probe);
assertEquals(20, probe.getInitialDelaySeconds().intValue());
assertNull(probe.getPeriodSeconds());
probe = enricher.getLivenessProbe();
assertNotNull(probe);
assertEquals(360, probe.getInitialDelaySeconds().intValue());
assertNull(probe.getPeriodSeconds());
}
Aggregations