use of org.hamcrest.CustomTypeSafeMatcher in project helios by spotify.
the class AuthenticatingHttpConnectorTest method matchesAnyEndpoint.
private CustomTypeSafeMatcher<URI> matchesAnyEndpoint(final String path) {
return new CustomTypeSafeMatcher<URI>("A URI matching one of the endpoints in " + endpoints) {
@Override
protected boolean matchesSafely(final URI item) {
for (final Endpoint endpoint : endpoints) {
final InetAddress ip = endpoint.getIp();
final URI uri = endpoint.getUri();
if (item.getScheme().equals(uri.getScheme()) && item.getHost().equals(ip.getHostAddress()) && item.getPath().equals(path)) {
return true;
}
}
return false;
}
};
}
use of org.hamcrest.CustomTypeSafeMatcher in project helios by spotify.
the class HealthCheckTest method execCompatibleDockerVersion.
private static Matcher<Version> execCompatibleDockerVersion() {
return new CustomTypeSafeMatcher<Version>("apiVersion >= 1.18") {
@Override
protected boolean matchesSafely(final Version version) {
try {
final Iterator<String> versionParts = Splitter.on('.').split(version.apiVersion()).iterator();
final int apiVersionMajor = Integer.parseInt(versionParts.next());
final int apiVersionMinor = Integer.parseInt(versionParts.next());
return apiVersionMajor == 1 && apiVersionMinor >= 18;
} catch (Exception e) {
return false;
}
}
};
}
use of org.hamcrest.CustomTypeSafeMatcher in project beam by apache.
the class DisplayDataMatchers method includesDisplayDataFor.
/**
* Create a matcher that matches if the examined {@link DisplayData} contains all display data
* registered from the specified subcomponent and namespace.
*/
public static Matcher<DisplayData> includesDisplayDataFor(final String path, final HasDisplayData subComponent) {
return new CustomTypeSafeMatcher<DisplayData>("includes subcomponent") {
@Override
protected boolean matchesSafely(DisplayData displayData) {
DisplayData subComponentData = subComponentData(path);
if (subComponentData.items().size() == 0) {
throw new UnsupportedOperationException("subComponent contains no display data; " + "cannot verify whether it is included");
}
DisplayDataComparison comparison = checkSubset(displayData, subComponentData, path);
return comparison.missingItems.isEmpty();
}
@Override
protected void describeMismatchSafely(DisplayData displayData, Description mismatchDescription) {
DisplayData subComponentDisplayData = subComponentData(path);
DisplayDataComparison comparison = checkSubset(displayData, subComponentDisplayData, path);
mismatchDescription.appendText("did not include:\n").appendValue(comparison.missingItems).appendText("\nNon-matching items:\n").appendValue(comparison.unmatchedItems);
}
private DisplayData subComponentData(final String path) {
return DisplayData.from(new HasDisplayData() {
@Override
public void populateDisplayData(DisplayData.Builder builder) {
builder.include(path, subComponent);
}
});
}
private DisplayDataComparison checkSubset(DisplayData displayData, DisplayData included, String path) {
DisplayDataComparison comparison = new DisplayDataComparison(displayData.items());
for (Item item : included.items()) {
Item matchedItem = displayData.asMap().get(DisplayData.Identifier.of(DisplayData.Path.absolute(path), item.getNamespace(), item.getKey()));
if (matchedItem != null) {
comparison.matched(matchedItem);
} else {
comparison.missing(item);
}
}
return comparison;
}
class DisplayDataComparison {
Collection<Item> missingItems;
Collection<Item> unmatchedItems;
DisplayDataComparison(Collection<Item> superset) {
missingItems = Sets.newHashSet();
unmatchedItems = Sets.newHashSet(superset);
}
void matched(Item supersetItem) {
unmatchedItems.remove(supersetItem);
}
void missing(Item subsetItem) {
missingItems.add(subsetItem);
}
}
};
}
use of org.hamcrest.CustomTypeSafeMatcher in project elasticsearch by elastic.
the class PipelineExecutionServiceTests method testExecuteBulkPipelineDoesNotExist.
public void testExecuteBulkPipelineDoesNotExist() {
CompoundProcessor processor = mock(CompoundProcessor.class);
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, processor));
BulkRequest bulkRequest = new BulkRequest();
IndexRequest indexRequest1 = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
bulkRequest.add(indexRequest1);
IndexRequest indexRequest2 = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("does_not_exist");
bulkRequest.add(indexRequest2);
@SuppressWarnings("unchecked") BiConsumer<IndexRequest, Exception> failureHandler = mock(BiConsumer.class);
@SuppressWarnings("unchecked") Consumer<Exception> completionHandler = mock(Consumer.class);
executionService.executeBulkRequest(bulkRequest.requests(), failureHandler, completionHandler);
verify(failureHandler, times(1)).accept(argThat(new CustomTypeSafeMatcher<IndexRequest>("failure handler was not called with the expected arguments") {
@Override
protected boolean matchesSafely(IndexRequest item) {
return item == indexRequest2;
}
}), argThat(new CustomTypeSafeMatcher<IllegalArgumentException>("failure handler was not called with the expected arguments") {
@Override
protected boolean matchesSafely(IllegalArgumentException iae) {
return "pipeline with id [does_not_exist] does not exist".equals(iae.getMessage());
}
}));
verify(completionHandler, times(1)).accept(null);
}
use of org.hamcrest.CustomTypeSafeMatcher in project helios by spotify.
the class ZooKeeperClusterIdTest method testAgent.
@Test
public void testAgent() throws Exception {
startDefaultMaster("--zk-cluster-id=" + zkClusterId);
startDefaultAgent(testHost(), "--zk-cluster-id=" + zkClusterId);
awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// Create job and deploy it
final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
deployJob(jobId, testHost());
final TaskStatus runningStatus = awaitTaskState(jobId, testHost(), RUNNING);
final String containerId = runningStatus.getContainerId();
// Delete the config node which contains the cluster ID and all the job definitions
zk().curatorWithSuperAuth().delete().deletingChildrenIfNeeded().forPath("/config");
// Sleep for a second so agent has a chance to react to deletion
Thread.sleep(1000);
// Make sure the agent didn't stop the job
try (final DockerClient docker = getNewDockerClient()) {
final List<Container> containers = docker.listContainers();
final CustomTypeSafeMatcher<Container> containerIdMatcher = new CustomTypeSafeMatcher<Container>("Container with id " + containerId) {
@Override
protected boolean matchesSafely(Container container) {
return container.id().equals(containerId);
}
};
assertContainersMatch(containers, containerIdMatcher);
}
}
Aggregations