Пример #1
0
  @Test
  public void testShutdownImmediately()
      throws UnrecoverableKeyException, KeyManagementException, KeyStoreException,
          NoSuchAlgorithmException, CertificateException, IOException, InterruptedException {
    final Object mutex = new Object();

    final TestListener listener = new TestListener(mutex);
    final ApnsConnection<SimpleApnsPushNotification> apnsConnection =
        new ApnsConnection<SimpleApnsPushNotification>(
            TEST_ENVIRONMENT,
            SSLTestUtil.createSSLContextForTestClient(),
            this.getEventLoopGroup(),
            listener);

    synchronized (mutex) {
      apnsConnection.connect();

      while (!listener.connectionSucceeded) {
        mutex.wait();
      }
    }

    assertTrue(listener.connectionSucceeded);

    synchronized (mutex) {
      apnsConnection.shutdownImmediately();

      while (!listener.connectionClosed) {
        mutex.wait();
      }
    }

    assertTrue(listener.connectionClosed);
  }
Пример #2
0
  @Test
  public void testShutdownImmediatelyBeforeConnect() throws Exception {
    final Object mutex = new Object();

    final TestListener listener = new TestListener(mutex);
    final ApnsConnection<SimpleApnsPushNotification> apnsConnection =
        new ApnsConnection<SimpleApnsPushNotification>(
            TEST_ENVIRONMENT,
            SSLTestUtil.createSSLContextForTestClient(),
            this.getEventLoopGroup(),
            listener);

    apnsConnection.shutdownImmediately();
  }
Пример #3
0
  @Test
  public void testWaitForPendingOperationsToFinish() throws Exception {
    // For the purposes of this test, we're happy just as long as we don't time out waiting for
    // writes to finish.

    {
      final Object mutex = new Object();

      final TestListener listener = new TestListener(mutex);
      final ApnsConnection<SimpleApnsPushNotification> apnsConnection =
          new ApnsConnection<SimpleApnsPushNotification>(
              TEST_ENVIRONMENT,
              SSLTestUtil.createSSLContextForTestClient(),
              this.getEventLoopGroup(),
              listener);

      apnsConnection.waitForPendingWritesToFinish();
      apnsConnection.shutdownImmediately();
    }

    {
      final Object mutex = new Object();

      final TestListener listener = new TestListener(mutex);
      final ApnsConnection<SimpleApnsPushNotification> apnsConnection =
          new ApnsConnection<SimpleApnsPushNotification>(
              TEST_ENVIRONMENT,
              SSLTestUtil.createSSLContextForTestClient(),
              this.getEventLoopGroup(),
              listener);

      synchronized (mutex) {
        apnsConnection.connect();

        while (!listener.connectionSucceeded) {
          mutex.wait();
        }
      }

      assertTrue(listener.connectionSucceeded);

      for (int i = 0; i < 1000; i++) {
        apnsConnection.sendNotification(this.createTestNotification());
      }

      apnsConnection.waitForPendingWritesToFinish();
      apnsConnection.shutdownGracefully();
    }
  }