public virtual void TestDecompressorPoolCounts() { // Get two decompressors and return them Decompressor decomp1 = CodecPool.GetDecompressor(codec); Decompressor decomp2 = CodecPool.GetDecompressor(codec); Assert.Equal(LeaseCountErr, 2, CodecPool.GetLeasedDecompressorsCount (codec)); CodecPool.ReturnDecompressor(decomp2); Assert.Equal(LeaseCountErr, 1, CodecPool.GetLeasedDecompressorsCount (codec)); CodecPool.ReturnDecompressor(decomp1); Assert.Equal(LeaseCountErr, 0, CodecPool.GetLeasedDecompressorsCount (codec)); CodecPool.ReturnDecompressor(decomp1); Assert.Equal(LeaseCountErr, 0, CodecPool.GetLeasedCompressorsCount (codec)); }
/// <exception cref="System.Exception"/> public virtual void TestMultiThreadedDecompressorPool() { int iterations = 4; ExecutorService threadpool = Executors.NewFixedThreadPool(3); LinkedBlockingDeque <Decompressor> queue = new LinkedBlockingDeque <Decompressor>(2 * iterations); Callable <bool> consumer = new _Callable_147(queue); Callable <bool> producer = new _Callable_156(this, queue); for (int i = 0; i < iterations; i++) { threadpool.Submit(consumer); threadpool.Submit(producer); } // wait for completion threadpool.Shutdown(); threadpool.AwaitTermination(1000, TimeUnit.Seconds); Assert.Equal(LeaseCountErr, 0, CodecPool.GetLeasedDecompressorsCount (codec)); }