This repository has been archived by the owner on Sep 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from spotify/rculbertson/tmp-job-prober
Custom probers can now be provided to each job
- Loading branch information
Showing
7 changed files
with
153 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
helios-testing/src/main/java/com/spotify/helios/testing/Deployer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2014 Spotify AB. | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.spotify.helios.testing; | ||
|
||
import com.spotify.helios.common.descriptors.Job; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public interface Deployer { | ||
|
||
TemporaryJob deploy(Job job, List<String> hosts, Set<String> waitPorts, Prober prober); | ||
|
||
TemporaryJob deploy(Job job, String hostFilter, Set<String> waitPorts, Prober prober); | ||
|
||
void readyToDeploy(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
helios-testing/src/test/java/com/spotify/helios/testing/ProberTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.spotify.helios.testing; | ||
|
||
import com.spotify.helios.client.HeliosClient; | ||
import com.spotify.helios.system.SystemTestBase; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import static com.spotify.helios.common.descriptors.HostStatus.Status.UP; | ||
import static java.util.concurrent.TimeUnit.MINUTES; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.experimental.results.PrintableResult.testResult; | ||
import static org.junit.experimental.results.ResultMatchers.isSuccessful; | ||
|
||
public class ProberTest extends SystemTestBase { | ||
|
||
private static HeliosClient client; | ||
private static String testHost; | ||
|
||
public static class OverrideDefaultProberTest { | ||
|
||
private MockProber defaultProber = new MockProber(); | ||
private MockProber overrideProber = new MockProber(); | ||
|
||
@Rule | ||
public final TemporaryJobs temporaryJobs = TemporaryJobs.builder() | ||
.client(client) | ||
.prober(defaultProber) | ||
.build(); | ||
|
||
@Before | ||
public void setup() { | ||
temporaryJobs.job() | ||
.command(IDLE_COMMAND) | ||
.port("default", 4711) | ||
.deploy(testHost); | ||
|
||
temporaryJobs.job() | ||
.command(IDLE_COMMAND) | ||
.port("override", 4712) | ||
.prober(overrideProber) | ||
.deploy(testHost); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
// Verify that the first job used the prober passed to the TemporaryJobs rule. | ||
assertThat(defaultProber.probed(), is(true)); | ||
// Verify that the second job used the prober that was passed to its builder. | ||
assertThat(overrideProber.probed(), is(true)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testOverrideDefaultProber() throws Exception { | ||
startDefaultMaster(); | ||
client = defaultClient(); | ||
testHost = testHost(); | ||
startDefaultAgent(testHost); | ||
awaitHostStatus(client, testHost, UP, LONG_WAIT_MINUTES, MINUTES); | ||
assertThat(testResult(OverrideDefaultProberTest.class), isSuccessful()); | ||
} | ||
|
||
private static class MockProber implements Prober { | ||
private boolean probed; | ||
|
||
@Override | ||
public boolean probe(String host, int port) { | ||
return probed = true; | ||
} | ||
|
||
public boolean probed() { | ||
return probed; | ||
} | ||
} | ||
|
||
} |