-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for client side FIFO Evictor. pr-link: #13339 change-id: cid-1b039bec331d002a3db73df943e6f741892a4231
- Loading branch information
1 parent
ceaaef4
commit 431cafa
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
core/client/fs/src/test/java/alluxio/client/file/cache/FIFOEvictorTest.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,89 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.client.file.cache; | ||
|
||
import alluxio.ConfigurationTestUtils; | ||
import alluxio.client.file.cache.evictor.FIFOEvictor; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests for the {@link FIFOEvictor} class. | ||
*/ | ||
public final class FIFOEvictorTest { | ||
private FIFOEvictor mEvictor; | ||
private final PageId mFirst = new PageId("1L", 2L); | ||
private final PageId mSecond = new PageId("3L", 4L); | ||
private final PageId mThird = new PageId("5L", 6L); | ||
private final PageId mFourth = new PageId("7L", 8L); | ||
|
||
/** | ||
* Sets up the instances. | ||
*/ | ||
@Before | ||
public void before() { | ||
mEvictor = new FIFOEvictor(ConfigurationTestUtils.defaults()); | ||
} | ||
|
||
@Test | ||
public void evictPutOrder() { | ||
mEvictor.updateOnPut(mFirst); | ||
mEvictor.updateOnPut(mSecond); | ||
mEvictor.updateOnPut(mThird); | ||
mEvictor.updateOnPut(mFourth); | ||
Assert.assertEquals(mFirst, mEvictor.evict()); | ||
} | ||
|
||
@Test | ||
public void evictPutAndGetOrder() { | ||
mEvictor.updateOnPut(mFirst); | ||
mEvictor.updateOnPut(mSecond); | ||
mEvictor.updateOnPut(mThird); | ||
mEvictor.updateOnPut(mFourth); | ||
mEvictor.updateOnGet(mFourth); | ||
mEvictor.updateOnGet(mFourth); | ||
mEvictor.updateOnGet(mFourth); | ||
Assert.assertEquals(mFirst, mEvictor.evict()); | ||
} | ||
|
||
@Test | ||
public void evictAfterDelete() { | ||
mEvictor.updateOnPut(mFirst); | ||
mEvictor.updateOnPut(mSecond); | ||
mEvictor.updateOnPut(mThird); | ||
mEvictor.updateOnPut(mFourth); | ||
mEvictor.updateOnDelete(mSecond); | ||
Assert.assertEquals(mFirst, mEvictor.evict()); | ||
mEvictor.updateOnDelete(mFirst); | ||
Assert.assertEquals(mThird, mEvictor.evict()); | ||
} | ||
|
||
@Test | ||
public void evictEmpty() { | ||
Assert.assertNull(mEvictor.evict()); | ||
} | ||
|
||
@Test | ||
public void evictAllGone() { | ||
mEvictor.updateOnPut(mFirst); | ||
mEvictor.updateOnPut(mSecond); | ||
mEvictor.updateOnPut(mThird); | ||
mEvictor.updateOnPut(mFourth); | ||
mEvictor.updateOnDelete(mFirst); | ||
mEvictor.updateOnDelete(mSecond); | ||
mEvictor.updateOnDelete(mThird); | ||
mEvictor.updateOnDelete(mFourth); | ||
Assert.assertNull(mEvictor.evict()); | ||
} | ||
} |