public void ResampleNoLeak() { ResourceLeakDetector.DetectionLevel preservedLevel = ResourceLeakDetector.Level; try { ResourceLeakDetector.Level = ResourceLeakDetector.DetectionLevel.Paranoid; var bufPool = new PooledByteBufferAllocator(100, 1000); IByteBuffer buffer = bufPool.Buffer(10); buffer.Release(); buffer = bufPool.Buffer(10); buffer.Release(); } finally { ResourceLeakDetector.Level = preservedLevel; } }
public void AllocationCounter() { var allocator = new PooledByteBufferAllocator( true, // preferDirect 0, // nHeapArena 1, // nDirectArena 8192, // pageSize 11, // maxOrder 0, // tinyCacheSize 0, // smallCacheSize 0 // normalCacheSize ); // create tiny buffer IByteBuffer b1 = allocator.Buffer(24); // create small buffer IByteBuffer b2 = allocator.Buffer(800); // create normal buffer IByteBuffer b3 = allocator.Buffer(8192 * 2); Assert.NotNull(b1); Assert.NotNull(b2); Assert.NotNull(b3); // then release buffer to deallocated memory while threadlocal cache has been disabled // allocations counter value must equals deallocations counter value Assert.True(b1.Release()); Assert.True(b2.Release()); Assert.True(b3.Release()); Assert.True(allocator.DirectArenas().Count >= 1); IPoolArenaMetric metric = allocator.DirectArenas()[0]; Assert.Equal(3, metric.NumDeallocations); Assert.Equal(3, metric.NumAllocations); Assert.Equal(1, metric.NumTinyDeallocations); Assert.Equal(1, metric.NumTinyAllocations); Assert.Equal(1, metric.NumSmallDeallocations); Assert.Equal(1, metric.NumSmallAllocations); Assert.Equal(1, metric.NumNormalDeallocations); Assert.Equal(1, metric.NumNormalAllocations); }
public void PooledBufferGrowTest(int bufferSize, int startSize, int[] writeSizes) { var alloc = new PooledByteBufferAllocator(); IByteBuffer buffer = alloc.Buffer(startSize); int wrote = 0; foreach (int size in writeSizes) { buffer.WriteBytes(Unpooled.WrappedBuffer(new byte[size])); wrote += size; } Assert.Equal(wrote, buffer.ReadableBytes); }
public void PooledBufferGrowTest(int bufferSize, int startSize, int[] writeSizes) { var alloc = new PooledByteBufferAllocator(bufferSize, int.MaxValue); IByteBuffer buffer = alloc.Buffer(startSize); int wrote = 0; foreach (int size in writeSizes) { buffer.WriteBytes(Unpooled.WrappedBuffer(new byte[size])); wrote += size; } Assert.Equal(wrote, buffer.ReadableBytes); }
public void Leak() { var eventListener = new ObservableEventListener(); Mock<IObserver<EventEntry>> logListener = this.mockRepo.Create<IObserver<EventEntry>>(); var eventTextFormatter = new EventTextFormatter(); Func<EventEntry, bool> leakPredicate = y => y.TryFormatAsString(eventTextFormatter).Contains("LEAK"); logListener.Setup(x => x.OnNext(It.Is<EventEntry>(y => leakPredicate(y)))).Verifiable(); logListener.Setup(x => x.OnNext(It.Is<EventEntry>(y => !leakPredicate(y)))); eventListener.Subscribe(logListener.Object); eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.Verbose); var bufPool = new PooledByteBufferAllocator(100, 1000); IByteBuffer buffer = bufPool.Buffer(10); buffer = null; GC.Collect(); GC.WaitForPendingFinalizers(); this.mockRepo.Verify(); }
public void Leak() { var eventListener = new ObservableEventListener(); Mock <IObserver <EventEntry> > logListener = this.mockRepo.Create <IObserver <EventEntry> >(); var eventTextFormatter = new EventTextFormatter(); Func <EventEntry, bool> leakPredicate = y => y.TryFormatAsString(eventTextFormatter).Contains("LEAK"); logListener.Setup(x => x.OnNext(It.Is <EventEntry>(y => leakPredicate(y)))).Verifiable(); logListener.Setup(x => x.OnNext(It.Is <EventEntry>(y => !leakPredicate(y)))); eventListener.Subscribe(logListener.Object); eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.Verbose); var bufPool = new PooledByteBufferAllocator(100, 1000); IByteBuffer buffer = bufPool.Buffer(10); buffer = null; GC.Collect(); GC.WaitForPendingFinalizers(); this.mockRepo.Verify(); }