package com.github.triceo.splitlog;

import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * To demonstrate the problem referenced here: {@link https
 * ://github.com/triceo/splitlog/pull/15}.
 * 
 */
public class LimitedMessageStoreTest extends DefaultTailerBaseTest {

    private static final int CAPACITY = 1;
    private static final int TIMEOUT_MILLIS = 10000;
    private ExecutorService es;

    @Before
    public void setUp() {
        this.es = Executors.newFixedThreadPool(2);
    }

    @After
    public void tearDown() {
        this.es.shutdownNow();
        try {
            this.es.awaitTermination(2, TimeUnit.SECONDS);
        } catch (final InterruptedException ex) {
            System.err.println("Executor service failed to terminate.");
        }
    }

    @Override
    protected LogWatchBuilder getBuilder() {
        return super.getBuilder().limitCapacityTo(LimitedMessageStoreTest.CAPACITY);
    }

    @Test(timeout = LimitedMessageStoreTest.TIMEOUT_MILLIS)
    public void testLimitedMessageStore() throws InterruptedException, ExecutionException {
        this.es.execute(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    LimitedMessageStoreTest.this.getWriter().writeWithoutWaiting(UUID.randomUUID().toString());
                }
            }
        });
        final LogTailer tailer = this.getLogWatch().startTailing();
        final Future<?> reader = this.es.submit(new Runnable() {
            @Override
            public void run() {
                final long maxMillis = LimitedMessageStoreTest.TIMEOUT_MILLIS / 2;
                final long start = System.currentTimeMillis();
                while ((System.currentTimeMillis() - start) < maxMillis) {
                    tailer.getMessages();
                }
            }
        });
        reader.get();
    }
}

@@ -344,68 +344,27 @@
 %0A * 
-To demonstrate the problem referenced
+@see %3Ca
  h
-e
 re
-: %7B@link 
+f=%22
 https
-%0A * 
 ://g
@@ -400,14 +400,33 @@
 l/15
-%7D.%0A * 
+%22%3ESplitlog Issue #15%3C/a%3E.
 %0A */

Fix javadoc