-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a test case for ElasticByteBufferPool
- Loading branch information
1 parent
a3c7fe7
commit 2151ea2
Showing
4 changed files
with
46 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...n-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestElasticByteBufferPool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.apache.hadoop.io; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.Test; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public class TestElasticByteBufferPool { | ||
@Test | ||
public void testGarbageCollection() throws Exception { | ||
final ElasticByteBufferPool ebbp = new WeakReferencedElasticByteBufferPool(); | ||
ByteBuffer buffer1 = ebbp.getBuffer(true, 5); | ||
ByteBuffer buffer2 = ebbp.getBuffer(true, 10); | ||
ByteBuffer buffer3 = ebbp.getBuffer(true, 15); | ||
|
||
// the pool is empty yet | ||
Assertions.assertThat(ebbp.getCurrentBuffersCount(true)).isEqualTo(0); | ||
|
||
// put the buffers back to the pool | ||
ebbp.putBuffer(buffer2); | ||
ebbp.putBuffer(buffer3); | ||
Assertions.assertThat(ebbp.getCurrentBuffersCount(true)).isEqualTo(2); | ||
|
||
// release the references to be garbage-collected | ||
buffer2 = null; | ||
buffer3 = null; | ||
System.gc(); | ||
|
||
// call getBuffer() to trigger the cleanup | ||
ByteBuffer buffer4 = ebbp.getBuffer(true, 10); | ||
|
||
// the pool should be empty. buffer2, buffer3 should be garbage-collected | ||
Assertions.assertThat(ebbp.getCurrentBuffersCount(true)).isEqualTo(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters