### Question:
SmcpDiscoveryQuery extends DiscoveryQuery { @Override public Set<Thing> get() throws InterruptedException, TechnologyException { if (!mTimeout.isCancelled()) { try { mTimeout.get(mTimeoutInMs, TimeUnit.MILLISECONDS); } catch (CancellationException | TimeoutException ignored) { } catch (ExecutionException x) { throw new TechnologyRuntimeException(x); } } if (mException instanceof TechnologyException) { throw (TechnologyException) mException; } else if (mException instanceof RuntimeException) { throw (RuntimeException) mException; } else if (mException != null) { throw new TechnologyException(mException); } synchronized (mThings) { return new HashSet<>(mThings); } } SmcpDiscoveryQuery(
            SmcpTechnology technology, Transaction transaction, long timeoutInMs, int maxResults); @Override void restart(); @Override Set<Thing> get(); @Override void stop(); @Override boolean isDone(); @Override void setListener(Executor executor, @Nullable Listener listener);  }### Answer:
@Test void normalDiscoveryLoopTest() throws Exception { try { SmcpTechnology techHosting = new SmcpTechnology(mContextA); SmcpTechnology techBacking = new SmcpTechnology(mContextA); MyLightBulb localFe = new MyLightBulb(); techHosting .getServer() .addLocalEndpoint( techHosting .getLocalEndpointManager() .getLocalEndpointForScheme("loop")); techHosting.host(localFe); techHosting.getServer().start(); DiscoveryQuery query = techBacking .createDiscoveryQueryBuilder() .setLocalEndpoint( techBacking .getLocalEndpointManager() .getLocalEndpointForScheme("loop")) .setTimeout(100, TimeUnit.MILLISECONDS) .buildAndRun(); tick(1); Set<Thing> results = query.get(); assertFalse(results.isEmpty()); assertEquals(1, results.size()); Thing remoteFe = results.iterator().next(); assertEquals( localFe.getCachedProperty(BaseTrait.META_UID), remoteFe.getCachedProperty(BaseTrait.META_UID)); } catch (Throwable x) { dumpLogs(); throw x; } }
@Test void normalDiscoveryCoapUdpTest() throws Exception { try { SmcpTechnology techHosting = new SmcpTechnology(mContextB); SmcpTechnology techBacking = new SmcpTechnology(mContextA); MyLightBulb localFe = new MyLightBulb(); LocalEndpoint hostingEndpoint = mContextA.getLocalEndpointForScheme(Coap.SCHEME_UDP); techHosting.getServer().addLocalEndpoint(hostingEndpoint); techHosting.prepareToHost(); techHosting.host(localFe); techHosting.getServer().start(); int port = 0; SocketAddress hostingSockaddr = hostingEndpoint.getLocalSocketAddress(); if (hostingSockaddr instanceof InetSocketAddress) { port = ((InetSocketAddress)hostingSockaddr).getPort(); } DiscoveryQuery query = techBacking .createDiscoveryQueryBuilder() .setTimeout(100, TimeUnit.MILLISECONDS) .setBaseUri(URI.create("coap: .buildAndRun(); Set<Thing> results = query.get(); assertFalse(results.isEmpty()); assertEquals(1, results.size()); Thing remoteFe = results.iterator().next(); assertEquals( localFe.getCachedProperty(BaseTrait.META_UID), remoteFe.getCachedProperty(BaseTrait.META_UID)); } catch (Throwable x) { dumpLogs(); throw x; } }