use of org.hamcrest.Matcher in project pulsar by yahoo.
the class NamespacesTest method testUnloadNamespaces.
@Test
public void testUnloadNamespaces() throws Exception {
final NamespaceName testNs = this.testLocalNamespaces.get(1);
URL localWebServiceUrl = new URL(pulsar.getWebServiceAddress());
doReturn(localWebServiceUrl).when(nsSvc).getWebServiceUrl(Mockito.argThat(new Matcher<NamespaceBundle>() {
@Override
public void describeTo(Description description) {
// TODO Auto-generated method stub
}
@Override
public boolean matches(Object item) {
if (item instanceof NamespaceName) {
NamespaceName ns = (NamespaceName) item;
return ns.equals(testNs);
}
return false;
}
@Override
public void _dont_implement_Matcher___instead_extend_BaseMatcher_() {
// TODO Auto-generated method stub
}
}), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean());
doReturn(true).when(nsSvc).isServiceUnitOwned(Mockito.argThat(new Matcher<NamespaceBundle>() {
@Override
public void describeTo(Description description) {
// TODO Auto-generated method stub
}
@Override
public boolean matches(Object item) {
if (item instanceof NamespaceName) {
NamespaceName ns = (NamespaceName) item;
return ns.equals(testNs);
}
return false;
}
@Override
public void _dont_implement_Matcher___instead_extend_BaseMatcher_() {
// TODO Auto-generated method stub
}
}));
doNothing().when(nsSvc).unloadNamespace(testNs);
NamespaceBundle bundle = nsSvc.getNamespaceBundleFactory().getFullBundle(testNs);
doNothing().when(namespaces).validateBundleOwnership(bundle, false, true);
try {
namespaces.unloadNamespace(testNs.getProperty(), testNs.getCluster(), testNs.getLocalName());
fail("should have failed as bydefault bundle is activated and can't be unloaded");
} catch (RestException re) {
// ok
}
verify(nsSvc, times(0)).unloadNamespace(testNs);
}
use of org.hamcrest.Matcher in project pulsar by yahoo.
the class NamespacesTest method testNamespacesApiRedirects.
@Test
public void testNamespacesApiRedirects() throws Exception {
// Redirect cases
uriField.set(namespaces, uriInfo);
doReturn(false).when(namespaces).isLeaderBroker();
URI uri = URI.create("http://localhost" + ":" + BROKER_WEBSERVICE_PORT + "/admin/namespace/" + this.testLocalNamespaces.get(2).toString());
doReturn(uri).when(uriInfo).getRequestUri();
// Trick to force redirection
conf.setAuthorizationEnabled(true);
try {
namespaces.deleteNamespace(this.testProperty, this.testOtherCluster, this.testLocalNamespaces.get(2).getLocalName(), false);
fail("Should have raised exception to redirect request");
} catch (WebApplicationException wae) {
// OK
assertEquals(wae.getResponse().getStatus(), Status.TEMPORARY_REDIRECT.getStatusCode());
assertEquals(wae.getResponse().getLocation().toString(), UriBuilder.fromUri(uri).host("broker-usc.com").port(BROKER_WEBSERVICE_PORT).toString());
}
uri = URI.create("http://localhost" + ":" + BROKER_WEBSERVICE_PORT + "/admin/namespace/" + this.testLocalNamespaces.get(2).toString() + "/unload");
doReturn(uri).when(uriInfo).getRequestUri();
try {
namespaces.unloadNamespaceBundle(this.testProperty, this.testOtherCluster, this.testLocalNamespaces.get(2).getLocalName(), "0x00000000_0xffffffff", false);
fail("Should have raised exception to redirect request");
} catch (WebApplicationException wae) {
// OK
assertEquals(wae.getResponse().getStatus(), Status.TEMPORARY_REDIRECT.getStatusCode());
assertEquals(wae.getResponse().getLocation().toString(), UriBuilder.fromUri(uri).host("broker-usc.com").port(BROKER_WEBSERVICE_PORT).toString());
}
uri = URI.create("http://localhost" + ":" + BROKER_WEBSERVICE_PORT + "/admin/namespace/" + this.testGlobalNamespaces.get(0).toString() + "/configversion");
doReturn(uri).when(uriInfo).getRequestUri();
// setup to redirect to another broker in the same cluster
doReturn(new URL("http://otherhost" + ":" + BROKER_WEBSERVICE_PORT)).when(nsSvc).getWebServiceUrl(Mockito.argThat(new Matcher<NamespaceName>() {
@Override
public void describeTo(Description description) {
// TODO Auto-generated method stub
}
@Override
public boolean matches(Object item) {
NamespaceName nsname = (NamespaceName) item;
return nsname.equals(NamespacesTest.this.testGlobalNamespaces.get(0));
}
@Override
public void _dont_implement_Matcher___instead_extend_BaseMatcher_() {
// TODO Auto-generated method stub
}
}), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean());
admin.namespaces().setNamespaceReplicationClusters(testGlobalNamespaces.get(0).toString(), Lists.newArrayList("usw"));
uri = URI.create("http://localhost" + ":" + BROKER_WEBSERVICE_PORT + "/admin/namespace/" + this.testLocalNamespaces.get(2).toString() + "?authoritative=false");
doReturn(uri).when(uriInfo).getRequestUri();
doReturn(true).when(namespaces).isLeaderBroker();
try {
namespaces.deleteNamespace(this.testLocalNamespaces.get(2).getProperty(), this.testLocalNamespaces.get(2).getCluster(), this.testLocalNamespaces.get(2).getLocalName(), false);
fail("Should have raised exception to redirect request");
} catch (WebApplicationException wae) {
// OK
assertEquals(wae.getResponse().getStatus(), Status.TEMPORARY_REDIRECT.getStatusCode());
assertEquals(wae.getResponse().getLocation().toString(), UriBuilder.fromUri(uri).host("broker-usc.com").port(BROKER_WEBSERVICE_PORT).toString());
}
}
use of org.hamcrest.Matcher in project beam by apache.
the class GcpApiSurfaceTest method testGcpApiSurface.
@Test
public void testGcpApiSurface() throws Exception {
final Package thisPackage = getClass().getPackage();
final ClassLoader thisClassLoader = getClass().getClassLoader();
final ApiSurface apiSurface = ApiSurface.ofPackage(thisPackage, thisClassLoader).pruningPattern(BigqueryMatcher.class.getName()).pruningPattern("org[.]apache[.]beam[.].*Test.*").pruningPattern("org[.]apache[.]beam[.].*IT").pruningPattern("java[.]lang.*").pruningPattern("java[.]util.*");
@SuppressWarnings("unchecked") final Set<Matcher<Class<?>>> allowedClasses = ImmutableSet.of(classesInPackage("com.google.api.client.googleapis"), classesInPackage("com.google.api.client.http"), classesInPackage("com.google.api.client.json"), classesInPackage("com.google.api.client.util"), classesInPackage("com.google.api.services.bigquery.model"), classesInPackage("com.google.auth"), classesInPackage("com.google.bigtable.v2"), classesInPackage("com.google.cloud.bigtable.config"), Matchers.<Class<?>>equalTo(com.google.cloud.bigtable.grpc.BigtableClusterName.class), Matchers.<Class<?>>equalTo(com.google.cloud.bigtable.grpc.BigtableInstanceName.class), Matchers.<Class<?>>equalTo(com.google.cloud.bigtable.grpc.BigtableTableName.class), Matchers.<Class<?>>equalTo(com.google.cloud.ByteArray.class), Matchers.<Class<?>>equalTo(com.google.cloud.Date.class), Matchers.<Class<?>>equalTo(com.google.cloud.Timestamp.class), classesInPackage("com.google.cloud.spanner"), classesInPackage("com.google.datastore.v1"), classesInPackage("com.google.protobuf"), classesInPackage("com.google.type"), classesInPackage("com.fasterxml.jackson.annotation"), classesInPackage("com.fasterxml.jackson.core"), classesInPackage("com.fasterxml.jackson.databind"), classesInPackage("io.grpc"), classesInPackage("java"), classesInPackage("javax"), classesInPackage("org.apache.beam"), classesInPackage("org.apache.commons.logging"), classesInPackage("org.joda.time"));
assertThat(apiSurface, containsOnlyClassesMatching(allowedClasses));
}
use of org.hamcrest.Matcher in project beam by apache.
the class ImmutableListBundleFactoryTest method afterCommitGetElementsShouldHaveAddedElements.
private <T> CommittedBundle<T> afterCommitGetElementsShouldHaveAddedElements(Iterable<WindowedValue<T>> elems) {
UncommittedBundle<T> bundle = bundleFactory.createRootBundle();
Collection<Matcher<? super WindowedValue<T>>> expectations = new ArrayList<>();
Instant minElementTs = BoundedWindow.TIMESTAMP_MAX_VALUE;
for (WindowedValue<T> elem : elems) {
bundle.add(elem);
expectations.add(equalTo(elem));
if (elem.getTimestamp().isBefore(minElementTs)) {
minElementTs = elem.getTimestamp();
}
}
Matcher<Iterable<? extends WindowedValue<T>>> containsMatcher = Matchers.<WindowedValue<T>>containsInAnyOrder(expectations);
Instant commitTime = Instant.now();
CommittedBundle<T> committed = bundle.commit(commitTime);
assertThat(committed.getElements(), containsMatcher);
// Sanity check that the test is meaningful.
assertThat(minElementTs, not(equalTo(commitTime)));
assertThat(committed.getMinTimestamp(), equalTo(minElementTs));
assertThat(committed.getSynchronizedProcessingOutputWatermark(), equalTo(commitTime));
return committed;
}
use of org.hamcrest.Matcher in project double-espresso by JakeWharton.
the class DrawerActions method checkDrawer.
/**
* Returns true if the given matcher matches the drawer.
*/
private static boolean checkDrawer(int drawerLayoutId, final Matcher<View> matcher) {
final AtomicBoolean matches = new AtomicBoolean(false);
onView(withId(drawerLayoutId)).perform(new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(DrawerLayout.class);
}
@Override
public String getDescription() {
return "check drawer";
}
@Override
public void perform(UiController uiController, View view) {
matches.set(matcher.matches(view));
}
});
return matches.get();
}
Aggregations