public static NetworkMultiplexer shared(Network net) {
        return new NetworkMultiplexer(net, true);
    }
@Test
    void testShared() {
        MockNetwork net = new MockNetwork();
        MockOwner owner1 = new MockOwner();
        MockOwner owner2 = new MockOwner();
        NetworkMultiplexer shared = NetworkMultiplexer.shared(net);
        assertEquals(Set.of(shared), net.attached);
        assertEquals(Set.of(), net.registered);
        assertFalse(net.shutDown.get());

        shared.attach(owner1);
        shared.registerSession("s1", owner1, true);
        try {
            shared.registerSession("s1", owner1, true);
            fail("Illegal to register same session multiple times with the same owner");
        }
        catch (IllegalArgumentException expected) {
            assertEquals("Session 's1' with owner 'mock owner' already registered with network multiplexer with owners: [mock owner], sessions: {s1=[mock owner]} and destructible: false",
                         expected.getMessage());
        }
        assertEquals(Set.of("s1"), net.registered);

        shared.attach(owner2);
        shared.registerSession("s2", owner2, true);
        shared.registerSession("s3", owner2, false);
        assertEquals(Set.of("s1", "s2"), net.registered);

        Utf8String name = new Utf8String("protocol");
        Protocol protocol1 = new SimpleProtocol();
        Protocol protocol2 = new SimpleProtocol();
        owner1.protocols.put(name, protocol1);
        assertEquals(protocol1, shared.getProtocol(name));
        owner2.protocols.put(name, protocol2);
        assertEquals(protocol2, shared.getProtocol(name));

        Message message1 = new SimpleMessage("one");
        Message message2 = new SimpleMessage("two");
        Message message3 = new SimpleMessage("three");
        Message message4 = new SimpleMessage("four");
        Message message5 = new SimpleMessage("five");
        shared.deliverMessage(message1, "s1");
        shared.deliverMessage(message2, "s2");

        // New "s1" owner connects, and should have new requests.
        shared.registerSession("s1", owner2, true);
        shared.deliverMessage(message3, "s1");
        shared.deliverMessage(message4, "s3");
        shared.unregisterSession("s1", owner1, true);
        shared.deliverMessage(message5, "s1");
        assertEquals(Map.of("s1", List.of(message1)), owner1.messages);
        assertEquals(Map.of("s2", List.of(message2), "s1", List.of(message3, message5), "s3", List.of(message4)), owner2.messages);

        shared.detach(owner1);
        assertEquals(protocol2, shared.getProtocol(name));

        shared.detach(owner2);
        assertFalse(net.shutDown.get());

        shared.attach(owner2);
        shared.disown();
        assertFalse(net.shutDown.get());

        shared.detach(owner2);
        assertTrue(net.shutDown.get());
    }