RegistryDNS extends AbstractService implements DNSOperations,
    ZoneSelector { @Override public void register(String path, ServiceRecord record) throws IOException { op(path, record, addRecordCommand); } RegistryDNS(String name); void initializeChannels(Configuration conf); byte[] formErrorMessage(byte[] in); void nioTCPClient(SocketChannel ch); void serveNIOTCP(ServerSocketChannel serverSocketChannel,
      InetAddress addr, int port); void addNIOTCP(final InetAddress addr, final int port); void addNIOUDP(final InetAddress addr, final int port); byte[] errorMessage(Message query, int rcode); RRset findExactMatch(Name name, int type); @Override Zone findBestZone(Name name); @Override void register(String path, ServiceRecord record); @Override void delete(String path, ServiceRecord record); static final String CONTAINER; static final String IN_ADDR_ARPA; static final String ZONE_SUFFIX; }
@Test public void testAppRegistration() throws Exception { ServiceRecord record = getMarshal().fromBytes("somepath", APPLICATION_RECORD.getBytes()); getRegistryDNS().register( "/registry/users/root/services/org-apache-slider/test1/", record); Record[] recs = assertDNSQuery("test1.root.dev.test."); assertEquals("wrong result", "192.168.1.5", ((ARecord) recs[0]).getAddress().getHostAddress()); recs = assertDNSQuery("management-api.test1.root.dev.test.", 2); assertEquals("wrong target name", "test1.root.dev.test.", ((CNAMERecord) recs[0]).getTarget().toString()); assertTrue("not an ARecord", recs[isSecure() ? 2 : 1] instanceof ARecord); recs = assertDNSQuery("appmaster-ipc-api.test1.root.dev.test.", Type.SRV, 1); assertTrue("not an SRV record", recs[0] instanceof SRVRecord); assertEquals("wrong port", 1026, ((SRVRecord) recs[0]).getPort()); recs = assertDNSQuery("appmaster-ipc-api.test1.root.dev.test.", 2); assertEquals("wrong target name", "test1.root.dev.test.", ((CNAMERecord) recs[0]).getTarget().toString()); assertTrue("not an ARecord", recs[isSecure() ? 2 : 1] instanceof ARecord); recs = assertDNSQuery("http-api.test1.root.dev.test.", 2); assertEquals("wrong target name", "test1.root.dev.test.", ((CNAMERecord) recs[0]).getTarget().toString()); assertTrue("not an ARecord", recs[isSecure() ? 2 : 1] instanceof ARecord); recs = assertDNSQuery("http-api.test1.root.dev.test.", Type.SRV, 1); assertTrue("not an SRV record", recs[0] instanceof SRVRecord); assertEquals("wrong port", 1027, ((SRVRecord) recs[0]).getPort()); assertDNSQuery("test1.root.dev.test.", Type.TXT, 3); assertDNSQuery("appmaster-ipc-api.test1.root.dev.test.", Type.TXT, 1); assertDNSQuery("http-api.test1.root.dev.test.", Type.TXT, 1); assertDNSQuery("management-api.test1.root.dev.test.", Type.TXT, 1); }
@Test public void testContainerRegistration() throws Exception { ServiceRecord record = getMarshal().fromBytes("somepath", CONTAINER_RECORD.getBytes()); getRegistryDNS().register( "/registry/users/root/services/org-apache-slider/test1/components/" + "ctr-e50-1451931954322-0016-01-000002", record); Record[] recs = assertDNSQuery("ctr-e50-1451931954322-0016-01-000002.dev.test."); assertEquals("wrong result", "172.17.0.19", ((ARecord) recs[0]).getAddress().getHostAddress()); recs = assertDNSQuery("httpd-1.test1.root.dev.test.", 1); assertTrue("not an ARecord", recs[0] instanceof ARecord); }
@Test public void testRecordTTL() throws Exception { ServiceRecord record = getMarshal().fromBytes("somepath", CONTAINER_RECORD.getBytes()); getRegistryDNS().register( "/registry/users/root/services/org-apache-slider/test1/components/" + "ctr-e50-1451931954322-0016-01-000002", record); Record[] recs = assertDNSQuery( "ctr-e50-1451931954322-0016-01-000002.dev.test."); assertEquals("wrong result", "172.17.0.19", ((ARecord) recs[0]).getAddress().getHostAddress()); assertEquals("wrong ttl", 30L, recs[0].getTTL()); recs = assertDNSQuery("httpd-1.test1.root.dev.test.", 1); assertTrue("not an ARecord", recs[0] instanceof ARecord); assertEquals("wrong ttl", 30L, recs[0].getTTL()); }
@Test public void testReverseLookup() throws Exception { ServiceRecord record = getMarshal().fromBytes("somepath", CONTAINER_RECORD.getBytes()); getRegistryDNS().register( "/registry/users/root/services/org-apache-slider/test1/components/" + "ctr-e50-1451931954322-0016-01-000002", record); Record[] recs = assertDNSQuery("19.0.17.172.in-addr.arpa.", Type.PTR, 1); assertEquals("wrong result", "httpd-1.test1.root.dev.test.", ((PTRRecord) recs[0]).getTarget().toString()); }
@Test public void testAAAALookup() throws Exception { ServiceRecord record = getMarshal().fromBytes("somepath", CONTAINER_RECORD.getBytes()); getRegistryDNS().register( "/registry/users/root/services/org-apache-slider/test1/components/" + "ctr-e50-1451931954322-0016-01-000002", record); Record[] recs = assertDNSQuery( "ctr-e50-1451931954322-0016-01-000002.dev.test.", Type.AAAA, 1); assertEquals("wrong result", "172.17.0.19", ((AAAARecord) recs[0]).getAddress().getHostAddress()); recs = assertDNSQuery("httpd-1.test1.root.dev.test.", Type.AAAA, 1); assertTrue("not an ARecord", recs[0] instanceof AAAARecord); }
@Test public void testMultiARecord() throws Exception { ServiceRecord record = getMarshal().fromBytes("somepath", CONTAINER_RECORD.getBytes()); ServiceRecord record2 = getMarshal().fromBytes("somepath", CONTAINER_RECORD2.getBytes()); getRegistryDNS().register( "/registry/users/root/services/org-apache-slider/test1/components/" + "ctr-e50-1451931954322-0016-01-000002", record); getRegistryDNS().register( "/registry/users/root/services/org-apache-slider/test1/components/" + "ctr-e50-1451931954322-0016-01-000003", record2); Record[] recs = assertDNSQuery("httpd.test1.root.dev.test.", 2); assertTrue("not an ARecord", recs[0] instanceof ARecord); assertTrue("not an ARecord", recs[1] instanceof ARecord); }