Search in sources :

Example 21 with SimpleBooleanProperty

use of javafx.beans.property.SimpleBooleanProperty in project bitsquare by bitsquare.

the class TorNetworkNode method networkNodeShutDown.

private BooleanProperty networkNodeShutDown() {
    final BooleanProperty done = new SimpleBooleanProperty();
    super.shutDown(() -> done.set(true));
    return done;
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty)

Example 22 with SimpleBooleanProperty

use of javafx.beans.property.SimpleBooleanProperty in project bitsquare by bitsquare.

the class StressTestMailboxMessage method test_mailbox.

// # DIRECT + MAILBOX SENDING AND RECEIVING
/**
     * Test sending and receiving mailbox messages.
     */
@Test
public void test_mailbox() throws InterruptedException {
    // We start by putting the first half of peers online and the second one offline.
    // Then the first online peer sends a number of messages to random peers (regardless of their state),
    // so that some messages are delivered directly and others into a mailbox.
    // Then the first online peer is put offline and the last offline peer is put online
    // (so it can get its mailbox messages),
    // and the new first online node sends messages.
    // This is repeated until all nodes have been online and offline.
    final int nPeers = peerNodes.size();
    // No sent latch here since the order of events is different
    // depending on whether the message goes direct or via mailbox.
    final CountDownLatch receivedMailboxLatch = new CountDownLatch(mailboxCount * nPeers);
    // Configure the first half of peers to receive messages...
    int firstPeerDown = (int) Math.ceil(nPeers / 2.0);
    for (P2PService peer : peerNodes.subList(0, firstPeerDown)) {
        addMailboxListeners(peer, receivedMailboxLatch);
    }
    // ...and put the second half offline.
    final CountDownLatch halfShutDown = new CountDownLatch(nPeers / 2);
    for (P2PService peer : peerNodes.subList(firstPeerDown, nPeers)) {
        peer.shutDown(halfShutDown::countDown);
    }
    assertLatch("timed out while stopping a half of the peers", halfShutDown, MAX_SHUTDOWN_DELAY_SECS * nPeers, TimeUnit.SECONDS);
    //print("stopped a half of the peers for mailbox test");
    // Cycle through peers sending to others, stopping the peer
    // and starting one of the stopped peers.
    print("%d mailbox messages to be sent by each of %d peers", mailboxCount, nPeers);
    BooleanProperty sentMailboxFailed = new SimpleBooleanProperty(false);
    final long sendStartMillis = System.currentTimeMillis();
    for (int firstOnline = 0, firstOffline = firstPeerDown; firstOnline < nPeers; firstOnline++, firstOffline = ++firstOffline % nPeers) {
        // The first online peer sends messages to random other peers.
        final P2PService onlinePeer = peerNodes.get(firstOnline);
        final NodeAddress onlinePeerAddress = onlinePeer.getAddress();
        final CountDownLatch sendLatch = new CountDownLatch(mailboxCount);
        for (int i = 0; i < mailboxCount; i++) {
            // Select a random peer (different than source one)...
            int peerIdx;
            NodeAddress peerAddr;
            do {
                peerIdx = (int) (Math.random() * nPeers);
                peerAddr = peerNodes.get(peerIdx).getAddress();
            } while (onlinePeerAddress.equals(peerAddr));
            final int dstPeerIdx = peerIdx;
            final NodeAddress dstPeerAddress = peerAddr;
            // ...and send a message to it.
            onlinePeer.sendEncryptedMailboxMessage(dstPeerAddress, peerPKRings.get(dstPeerIdx), new StressTestMailboxMessage(onlinePeerAddress, "test/" + dstPeerAddress), new // checked in receiver
            SendMailboxMessageListener() {

                @Override
                public void onArrived() {
                    sendLatch.countDown();
                }

                @Override
                public void onStoredInMailbox() {
                    sendLatch.countDown();
                }

                @Override
                public void onFault(String errorMessage) {
                    sentMailboxFailed.set(true);
                    sendLatch.countDown();
                }
            });
        }
        assertLatch("timed out while sending from peer " + firstOnline, sendLatch, MAILBOX_DELAY_SECS * mailboxCount, TimeUnit.SECONDS);
        // When done, put first online peer offline.
        final CountDownLatch stopLatch = new CountDownLatch(1);
        onlinePeer.shutDown(stopLatch::countDown);
        assertLatch("timed out while stopping peer " + firstOnline, stopLatch, MAX_SHUTDOWN_DELAY_SECS, TimeUnit.SECONDS);
        //print("put peer %d offline", firstOnline);
        // When done, put first offline peer online and setup message listeners.
        final CountDownLatch startLatch = new CountDownLatch(1);
        final P2PService startedPeer = createPeerNode(firstOffline, peerPorts.get(firstOffline));
        addMailboxListeners(startedPeer, receivedMailboxLatch);
        peerNodes.set(firstOffline, startedPeer);
        startedPeer.start(new MailboxStartListener(startLatch));
        assertLatch("timed out while starting peer " + firstOffline, startLatch, // this assumes some delay per received mailbox message
        (MAX_PRELIMINARY_DELAY_SECS + MAX_BOOTSTRAP_DELAY_SECS) + MAILBOX_DELAY_SECS * nPeers, TimeUnit.SECONDS);
    //print("put peer %d online", firstOffline);
    }
    /** Time to transmit all messages with the estimated per-message delay, with no computation delays. */
    final long idealMaxMailboxDelay = 2 * MAILBOX_DELAY_SECS * 1000 * nPeers * mailboxCount;
    assertLatch("timed out while receiving mailbox messages", receivedMailboxLatch, idealMaxMailboxDelay, TimeUnit.MILLISECONDS);
    final long recvMillis = System.currentTimeMillis() - sendStartMillis;
    print("receiving %d mailbox messages per peer took %ss (%.2f x ideal max)", mailboxCount, recvMillis / 1000.0, recvMillis / (float) idealMaxMailboxDelay);
    org.junit.Assert.assertFalse("some peer(s) failed to send a message", sentMailboxFailed.get());
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 23 with SimpleBooleanProperty

use of javafx.beans.property.SimpleBooleanProperty in project bitsquare by bitsquare.

the class StressTestMailboxMessage method setUp.

// # TEST SETUP
@Before
public void setUp() throws Exception {
    // Parse test parameter environment variables.
    /** Number of peer nodes to create. */
    final int nPeers = parseEnvInt(NPEERS_ENVVAR, NPEERS_DEFAULT, NPEERS_MIN);
    directCount = parseEnvInt(DIRECT_COUNT_ENVVAR, DIRECT_COUNT_DEFAULT, 0);
    mailboxCount = parseEnvInt(MAILBOX_COUNT_ENVVAR, MAILBOX_COUNT_DEFAULT, 0);
    /** A property where threads can indicate setup failure of local services (Tor node, hidden service). */
    final BooleanProperty localServicesFailed = new SimpleBooleanProperty(false);
    /** A barrier to wait for concurrent setup of local services (Tor node, hidden service). */
    final CountDownLatch localServicesLatch = new CountDownLatch(1 + /*seed node*/
    nPeers);
    /* A barrier to wait for concurrent reception of preliminary data in peers. */
    final CountDownLatch prelimDataLatch = new CountDownLatch(nPeers);
    /* A barrier to wait for concurrent bootstrap of peers. */
    final CountDownLatch bootstrapLatch = new CountDownLatch(nPeers);
    // Set a security provider to allow key generation.
    Security.addProvider(new BouncyCastleProvider());
    // Create the test data directory.
    testDataDir = createTestDataDirectory();
    print("test data directory: " + testDataDir);
    // Setting the executor seems to make tests more stable against ``ConcurrentModificationException``
    // (see #443).  However it make it use more open files, so you may need to use ``ulimit -n NUMBER``
    // or run ``prlimit -nNUMBER -pPID`` (as root) on your shell's PID if you get too many open files errors.
    // NUMBER=16384 seems to be enough for 100 peers in Debian GNU/Linux.
    UserThread.setExecutor(Executors.newSingleThreadExecutor());
    // Create and start the seed node.
    seedNode = new DummySeedNode(testDataDir.toString());
    final NodeAddress seedNodeAddress = newSeedNodeAddress();
    useLocalhost = seedNodeAddress.hostName.equals("localhost");
    final Set<NodeAddress> seedNodes = new HashSet<>(1);
    // the only seed node in tests
    seedNodes.add(seedNodeAddress);
    seedNode.createAndStartP2PService(seedNodeAddress, DummySeedNode.MAX_CONNECTIONS_DEFAULT, useLocalhost, REGTEST_NETWORK_ID, USE_DETAILED_LOGGING, seedNodes, new SeedServiceListener(localServicesLatch, localServicesFailed));
    print("created seed node");
    // Create and start peer nodes, all connecting to the seed node above.
    if (useLocalhost) {
        seedNodesRepository.setLocalhostSeedNodeAddresses(seedNodes);
    } else {
        seedNodesRepository.setTorSeedNodeAddresses(seedNodes);
    }
    for (int p = 0; p < nPeers; p++) {
        // peer network port
        final int peerPort = Utils.findFreeSystemPort();
        peerPorts.add(peerPort);
        // create, save and start peer
        final P2PService peer = createPeerNode(p, peerPort);
        //noinspection ConstantConditions
        peerPKRings.add(peer.getKeyRing().getPubKeyRing());
        peerNodes.add(peer);
        peer.start(new PeerServiceListener(localServicesLatch, localServicesFailed, prelimDataLatch, bootstrapLatch));
    }
    print("created peer nodes");
    // Wait for concurrent tasks to finish.
    localServicesLatch.await();
    // Check if any node reported setup failure on start.
    if (localServicesFailed.get()) {
        throw new Exception("nodes failed to start");
    }
    print("all local nodes started");
    // Wait for peers to get their preliminary data.
    assertLatch("timed out while waiting for preliminary data", prelimDataLatch, MAX_PRELIMINARY_DELAY_SECS * nPeers, TimeUnit.SECONDS);
    print("preliminary data received");
    // Wait for peers to complete their bootstrapping.
    assertLatch("timed out while waiting for bootstrap", bootstrapLatch, MAX_BOOTSTRAP_DELAY_SECS * nPeers, TimeUnit.SECONDS);
    print("bootstrap complete");
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Before(org.junit.Before)

Example 24 with SimpleBooleanProperty

use of javafx.beans.property.SimpleBooleanProperty in project bitsquare by bitsquare.

the class StressTestMailboxMessage method test_direct.

// # DIRECT SENDING AND RECEIVING
/**
     * Test each peer sending a direct message to another random peer.
     */
@Test
public void test_direct() throws InterruptedException {
    final int nPeers = peerNodes.size();
    BooleanProperty sentDirectFailed = new SimpleBooleanProperty(false);
    final List<Long> sentDelays = new Vector<>(nPeers * directCount);
    final CountDownLatch sentDirectLatch = new CountDownLatch(directCount * nPeers);
    final CountDownLatch receivedDirectLatch = new CountDownLatch(directCount * nPeers);
    final long sendStartMillis = System.currentTimeMillis();
    for (final P2PService srcPeer : peerNodes) {
        final NodeAddress srcPeerAddress = srcPeer.getAddress();
        // Make the peer ready for receiving direct messages.
        srcPeer.addDecryptedDirectMessageListener((decryptedMsgWithPubKey, peerNodeAddress) -> {
            if (!(decryptedMsgWithPubKey.message instanceof StressTestDirectMessage))
                return;
            StressTestDirectMessage directMessage = (StressTestDirectMessage) (decryptedMsgWithPubKey.message);
            if ((directMessage.getData().equals("test/" + srcPeerAddress)))
                receivedDirectLatch.countDown();
        });
        long nextSendMillis = System.currentTimeMillis();
        for (int i = 0; i < directCount; i++) {
            // Select a random peer (different than source one) and send a direct message to it...
            int peerIdx;
            NodeAddress peerAddr;
            do {
                peerIdx = (int) (Math.random() * nPeers);
                peerAddr = peerNodes.get(peerIdx).getAddress();
            } while (srcPeerAddress.equals(peerAddr));
            final int dstPeerIdx = peerIdx;
            final NodeAddress dstPeerAddress = peerAddr;
            // ...after a random delay not shorter than throttle limits.
            nextSendMillis += Math.round(Math.random() * (MAX_DIRECT_DELAY_MILLIS - MIN_DIRECT_DELAY_MILLIS));
            final long sendAfterMillis = nextSendMillis - System.currentTimeMillis();
            /*print("sending direct message from peer %s to %s in %sms",
                        srcPeer.getAddress(), dstPeer.getAddress(), sendAfterMillis);*/
            UserThread.runAfter(() -> {
                final long sendMillis = System.currentTimeMillis();
                srcPeer.sendEncryptedDirectMessage(dstPeerAddress, peerPKRings.get(dstPeerIdx), new StressTestDirectMessage("test/" + dstPeerAddress), new SendDirectMessageListener() {

                    @Override
                    public void onArrived() {
                        sentDelays.add(System.currentTimeMillis() - sendMillis);
                        countDownAndPrint(sentDirectLatch, 'd');
                    }

                    @Override
                    public void onFault() {
                        sentDirectFailed.set(true);
                        countDownAndPrint(sentDirectLatch, 'd');
                    }
                });
            }, sendAfterMillis, TimeUnit.MILLISECONDS);
        }
    }
    print("%d direct messages scheduled to be sent by each of %d peers", directCount, nPeers);
    // Since receiving is completed before sending is reported to be complete,
    // all receiving checks should end before all sending checks to avoid deadlocking.
    /** Time to transmit all messages in the worst random case, and with no computation delays. */
    final long idealMaxDirectDelay = MAX_DIRECT_DELAY_MILLIS * directCount;
    // Wait for peers to complete receiving.  We are generous here.
    assertLatch("timed out while receiving direct messages", receivedDirectLatch, 25 * idealMaxDirectDelay, TimeUnit.MILLISECONDS);
    final long recvMillis = System.currentTimeMillis() - sendStartMillis;
    print("receiving %d direct messages per peer took %ss (%.2f x ideal max)", directCount, recvMillis / 1000.0, recvMillis / (float) idealMaxDirectDelay);
    // Wait for peers to complete sending.
    // This should be nearly instantaneous after waiting for reception is completed.
    assertLatch("timed out while sending direct messages", sentDirectLatch, idealMaxDirectDelay / 10, TimeUnit.MILLISECONDS);
    Tuple3<Long, Long, Long> mma = minMaxAvg(sentDelays);
    print("sending %d direct messages per peer took %ss (min/max/avg %s/%s/%s ms)", directCount, (System.currentTimeMillis() - sendStartMillis) / 1000.0, mma.first, mma.second, mma.third);
    org.junit.Assert.assertFalse("some peer(s) failed to send a direct message", sentDirectFailed.get());
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 25 with SimpleBooleanProperty

use of javafx.beans.property.SimpleBooleanProperty in project Gargoyle by callakrsos.

the class ButtonTableColumn method initialize.

private void initialize(String buttonText, Function<Integer, Boolean> changeFunc) {
    this.changeFunc = changeFunc == null ? (i -> true) : changeFunc;
    this.setStyle(" -fx-alignment: CENTER;");
    ButtonCellFactory value = new ButtonCellFactory(buttonText, this);
    this.setCellFactory(value);
    this.setCellValueFactory(p -> new SimpleBooleanProperty(p.getValue() != null));
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty)

Aggregations

SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)46 BooleanProperty (javafx.beans.property.BooleanProperty)22 Test (org.junit.Test)7 FXCollections (javafx.collections.FXCollections)6 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)5 FXML (javafx.fxml.FXML)5 UserThread (bisq.common.UserThread)4 MockedProperty (com.canoo.dp.impl.remoting.MockedProperty)4 Binding (com.canoo.platform.core.functional.Binding)4 ReadOnlyStringWrapper (javafx.beans.property.ReadOnlyStringWrapper)4 P2PServiceListener (bisq.network.p2p.P2PServiceListener)3 CloseConnectionReason (bisq.network.p2p.network.CloseConnectionReason)3 Connection (bisq.network.p2p.network.Connection)3 ConnectionListener (bisq.network.p2p.network.ConnectionListener)3 Arrays (java.util.Arrays)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 StringProperty (javafx.beans.property.StringProperty)3 ChangeListener (javafx.beans.value.ChangeListener)3 TableColumn (javafx.scene.control.TableColumn)3 Inject (javax.inject.Inject)3