Class MockApnsServer


  • public class MockApnsServer
    extends Object

    A mock APNs server is an HTTP/2 server that can be configured to respond to APNs push notifications with a variety of behaviors. Mock servers are primarily useful for integration tests and benchmarks; users do not need to interact with mock servers as part of normal client operation.

    Callers construct mock APNs servers with the MockApnsServerBuilder class, and provide a PushNotificationHandlerFactory at construction time. The factory constructs PushNotificationHandler instances that control how the server responds to push notifications. Pushy comes with a ValidatingPushNotificationHandlerFactory that constructs handlers that emulate the behavior of a real APNs server (but do not actually deliver push notifications to destination devices) and an AcceptAllPushNotificationHandlerFactory that constructs handlers that unconditionally accept push notifications. Additionally, callers may specify a MockApnsServerListener that will be notified when notifications are accepted or rejected by the server.

    Since:
    0.8
    Author:
    Jon Chambers
    • Method Detail

      • start

        public Future<Void> start​(int port)
        Starts this mock server and listens for traffic on the given port.
        Parameters:
        port - the port to which this server should bind
        Returns:
        a Future that will succeed when the server has bound to the given port and is ready to accept traffic
      • shutdown

        public Future<Void> shutdown()

        Shuts down this server and releases the port to which this server was bound. If a null event loop group was provided at construction time, the server will also shut down its internally-managed event loop group.

        If a non-null EventLoopGroup was provided at construction time, mock servers may be reconnected and reused after they have been shut down. If no event loop group was provided at construction time, mock servers may not be restarted after they have been shut down via this method.

        Returns:
        a Future that will succeed once the server has finished unbinding from its port and, if the server was managing its own event loop group, its event loop group has shut down