// Path: src/test/java/com/zaxxer/nuprocess/CatTest.java
// private static byte[] getLotsOfBytes()
// {
//    return getLotsOfBytes(6000);
// }


import java.nio.ByteBuffer;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.Adler32;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static com.zaxxer.nuprocess.CatTest.getLotsOfBytes;
         {
            count.addAndGet(buffer.remaining());
            buffer.position(buffer.limit());
         }
      };

      NuProcessBuilder pb = new NuProcessBuilder(processListener, command);
      NuProcess nuProcess = pb.start();
      // TODO: given a large i (e.g. 1,000, 10,000), this unit test (testConsecutiveWrites) will
      //       produce a side-effect on InterruptTest (has problem on Mac OS X, but works on Linux and Win32).
      //       We do not reuse fork on surefire (reuseForks=false) to address this issue for now.
      for (int i = 0; i < 1000; i++) {
         ByteBuffer buffer = ByteBuffer.allocate(64);
         buffer.put("This is a test".getBytes());
         buffer.flip();
         nuProcess.writeStdin(buffer);
      }

      Thread.sleep(500);

      nuProcess.closeStdin(true);
      nuProcess.waitFor(20, TimeUnit.SECONDS);
      Assert.assertEquals("Count did not match", 14000, count.get());
   }


   @Test
   public void lotOfDataSync() throws Exception
   {
      System.err.println("Starting test lotOfDataSync()");
// Path: src/test/java/com/zaxxer/nuprocess/CatTest.java
// private static byte[] getLotsOfBytes()
// {
//    return getLotsOfBytes(6000);
// }


// Path: src/test/java/com/zaxxer/nuprocess/DirectWriteTest.java
import java.nio.ByteBuffer;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.Adler32;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static com.zaxxer.nuprocess.CatTest.getLotsOfBytes;

         {
            count.addAndGet(buffer.remaining());
            buffer.position(buffer.limit());
         }
      };

      NuProcessBuilder pb = new NuProcessBuilder(processListener, command);
      NuProcess nuProcess = pb.start();
      // TODO: given a large i (e.g. 1,000, 10,000), this unit test (testConsecutiveWrites) will
      //       produce a side-effect on InterruptTest (has problem on Mac OS X, but works on Linux and Win32).
      //       We do not reuse fork on surefire (reuseForks=false) to address this issue for now.
      for (int i = 0; i < 1000; i++) {
         ByteBuffer buffer = ByteBuffer.allocate(64);
         buffer.put("This is a test".getBytes());
         buffer.flip();
         nuProcess.writeStdin(buffer);
      }

      Thread.sleep(500);

      nuProcess.closeStdin(true);
      nuProcess.waitFor(20, TimeUnit.SECONDS);
      Assert.assertEquals("Count did not match", 14000, count.get());
   }


   @Test
   public void lotOfDataSync() throws Exception
   {
      System.err.println("Starting test lotOfDataSync()");
      final byte[] bytes = getLotsOfBytes(34632);