@Test(timeout = 5000)
    public void cacheLengthNotification() throws InterruptedException {

        server = new ApnsServerStub(FixedCertificates.serverContext().getServerSocketFactory());
        final CountDownLatch sync = new CountDownLatch(1);
        int ORIGINAL_CACHE_LENGTH = 100;
        final AtomicInteger modifiedCacheLength = new AtomicInteger();
        server.getWaitForError().acquire();
        server.start();
        ApnsService service =
                APNS.newService().withSSLContext(clientContext())
                .withGatewayDestination(LOCALHOST, server.getEffectiveGatewayPort())
                .withDelegate(new ApnsDelegate() {
            public void messageSent(ApnsNotification message, boolean resent) {

            }

            public void messageSendFailed(ApnsNotification message, Throwable e) {
            }

            public void connectionClosed(DeliveryError e, int messageIdentifier) {
            }

            public void cacheLengthExceeded(int newCacheLength) {
                modifiedCacheLength.set(newCacheLength);
                sync.countDown();
            }

            public void notificationsResent(int resendCount) {
            }
        })
                .build();
        server.stopAt(eMsg1.length() * 5 + eMsg2.length() + eMsg3.length() * 14);
        for (int i = 0; i < 5; ++i) {
            service.push(eMsg1);
        }


        service.push(eMsg2);

        for (int i = 0; i < 101; ++i) {
            service.push(eMsg3);
        }

        server.sendError(8, eMsg2.getIdentifier());

        server.getWaitForError().release();
        server.getMessages().acquire();

        sync.await();


        Assert.assertTrue(ORIGINAL_CACHE_LENGTH < modifiedCacheLength.get());
    }
Test to make sure that if the cache length is violated we get
a notification

@throws InterruptedException
src/test/java/com/notnoop/apns/integration/ApnsConnectionCacheTest.java