Node implements Closeable { public ModuleMailbox.NewMailboxBuilder mailbox () { return moduleMailbox.mailbox(); } @Builder private  Node(@NonNull NodeDescriptor descriptor,
                @NonNull Meta meta,
                @NonNull EpmdClient epmd,
                int creation,
                @NonNull NodeConfig config
  ); RemoteNode lookup(String name); RemoteNode lookup(ErlangPid pid); RemoteNode lookup(NodeDescriptor nodeDescriptor); boolean ping(String name); boolean ping(NodeDescriptor nodeDescriptor); boolean ping(RemoteNode remote); ErlangReference newReference(); ModuleMailbox.NewMailboxBuilder mailbox(); boolean register(Mailbox mailbox, String name); void deregister(String name); Mailbox mailbox(String name); Mailbox mailbox(ErlangPid pid); void remove(Mailbox mailbox); void remove(String name); void remove(ErlangPid pid); Map<ErlangPid, Mailbox> mailboxes(); CompletableFuture<Connection> connectAsync(RemoteNode remote); Connection connect(RemoteNode remote); Connection connect(RemoteNode remote, long timeout, TimeUnit unit); boolean isAvailable(RemoteNode remote); @Override void close();  }
@Test public void instantiating () throws Exception { val name = createName(); node = Nodes.singleNode(name, NodeConfig.builder() .shortName(true) .mailbox(MailboxConfig.builder() .name("one") .build()) .mailbox(MailboxConfig.builder() .name("two") .build()) .build() ); assertThat(node.mailbox("one")).isNotNull(); assertThat(node.mailbox("two")).isNotNull(); assertThat(node.mailbox("three")).isNull(); }
@Test public void sendFromOneToAnotherNode () throws Exception { val name1 = createName(); val name2 = createName(); node = Nodes.singleNode(name1, true); Mailbox mailbox1 = node.mailbox() .name("popa1") .build(); try (val node2 = Nodes.singleNode(name2, true)) { String text1 = "Hello world 1"; String text2 = "Hello world 2"; Mailbox mailbox2 = node2.mailbox() .name("popa2") .build(); mailbox2.send(name1, "popa1", string(text1)); assertThat(mailbox1.receive().getBody().asText()) .isEqualTo(text1); mailbox1.send(name2, "popa2", string(text2)); assertThat(mailbox2.receive().getBody().asText()) .isEqualTo(text2); } }
@Test public void link () throws Exception { val name = createName(); node = Nodes.singleNode(name, true); Mailbox mailbox1 = node.mailbox().build(); Mailbox mailbox2 = node.mailbox().build(); mailbox1.link(mailbox2.getPid()); SECONDS.sleep(1); mailbox2.unlink(mailbox1.getPid()); SECONDS.sleep(1); mailbox1.exit("popa"); try { mailbox2.receive(); } catch (ReceivedExitException ex) { assertThat(ex.getFrom()) .isEqualTo(mailbox1.getPid()); assertThat(ex.getReason()) .isEqualTo(new ErlangAtom("popa")); return; } assertThat(false).isTrue(); }
@Test public void exit () throws Exception { val name = createName(); node = Nodes.singleNode(name, true); Mailbox mailbox1 = node.mailbox().build(); Mailbox mailbox2 = node.mailbox().build(); mailbox2.link(mailbox1.getPid()); SECONDS.sleep(1); mailbox2.exit("popa"); try { mailbox1.receive(); } catch (ReceivedExitException ex) { assertThat(ex.getFrom()) .isEqualTo(mailbox2.getPid()); assertThat(ex.getReason()) .isEqualTo(new ErlangAtom("popa")); return; } assertThat(false).isTrue(); }
@Test public void remoteProcedureCall () throws Exception { val name = createName(); node = Nodes.singleNode(name, NodeConfig.builder() .shortName(true) .cookie("secret") .build()); Mailbox mailbox = node.mailbox().build(); mailbox.call(ELIXIR_ECHO_SERVER, "erlang", "date"); Message message = mailbox.receive(5, SECONDS); assertThat(message.getHeader()) .extracting(ControlMessage::getTag) .isEqualTo(SEND); assertThat(message.getBody()) .isNotNull(); ErlangTerm term = message.getBody(); assertThat(term.isTuple()).isTrue(); assertThat(term.size()).isEqualTo(2); assertThat(term.getUnsafe(0).asText()).isEqualTo("rex"); assertThat(term.getUnsafe(1).isTuple()).isTrue(); ErlangTerm response1 = term.getUnsafe(1); assertThat(response1.getUnsafe(0).isNumber()).isTrue(); assertThat(response1.getUnsafe(1).isNumber()).isTrue(); assertThat(response1.getUnsafe(2).isNumber()).isTrue(); mailbox.call(ELIXIR_ECHO_SERVER, "erlang", "date"); ErlangTerm response2 = mailbox.receiveRemoteProcedureResult(5, SECONDS); assertThat(response2).isEqualTo(response1); }