/*
 * Licensed to the University of California, Berkeley under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package tachyon.worker.block.evictor;

import java.io.File;
import java.util.Collections;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import tachyon.worker.block.BlockMetadataManager;
import tachyon.worker.block.BlockMetadataManagerView;

/*
 * Test EvictorFactory by passing different AllocatorType 
 * and test if it generate the correct Evictor instance.
 */
public class EvictorFactoryTest {
  private static BlockMetadataManager sBlockMetadataManager;
  private static BlockMetadataManagerView sBlockMetadataManagerView;
  
  @Rule
  public TemporaryFolder mTestFolder = new TemporaryFolder();

  @Before
  public void before() throws Exception {
    File tempFolder = mTestFolder.newFolder();
    if (sBlockMetadataManagerView == null) {
      if (sBlockMetadataManager == null) {
        sBlockMetadataManager = EvictorTestUtils.defaultMetadataManager(
           tempFolder.getAbsolutePath());
      }
      sBlockMetadataManagerView = new BlockMetadataManagerView(sBlockMetadataManager, 
          Collections.<Integer>emptySet(), Collections.<Long>emptySet());
    }
  }
  
  @Test
  public void createGreedyAllocatorTest() {
    Evictor evictor = EvictorFactory.create(EvictorType.GREEDY, sBlockMetadataManagerView);
    Assert.assertTrue(evictor instanceof GreedyEvictor);
  }
  
  @Test
  public void createLRUAllocatorTest() {
    Evictor evictor = EvictorFactory.create(EvictorType.LRU, sBlockMetadataManagerView);
    Assert.assertTrue(evictor instanceof LRUEvictor);
  }
  
  @Test
  public void createDefaultAllocatorTest() {
    Evictor evictor = EvictorFactory.create(EvictorType.DEFAULT, sBlockMetadataManagerView);
    Assert.assertTrue(evictor instanceof LRUEvictor);
  }
}

@@ -1010,24 +1010,83 @@
 aryFolder;%0A%0A
+import tachyon.Constants;%0Aimport tachyon.conf.TachyonConf;%0A
 import tachy
@@ -1239,20 +1239,16 @@
 torType 
-%0A * 
 and test
@@ -1274,16 +1274,19 @@
  correct
+%0A *
  Evictor
@@ -1464,18 +1464,16 @@
 erView;%0A
-  
 %0A  @Rule
@@ -1754,16 +1754,28 @@
 anager =
+%0A           
  Evictor
@@ -1807,28 +1807,16 @@
 Manager(
-%0A           
 tempFold
@@ -1879,16 +1879,26 @@
 erView =
+%0A         
  new Blo
@@ -1942,27 +1942,16 @@
 anager, 
-%0A          
 Collecti
@@ -1974,16 +1974,30 @@
 tySet(),
+%0A             
  Collect
@@ -2026,26 +2026,24 @@
 ;%0A    %7D%0A  %7D%0A
-  
 %0A  @Test%0A  p
@@ -2075,32 +2075,158 @@
 locatorTest() %7B%0A
+    TachyonConf conf = new TachyonConf();%0A    conf.set(Constants.WORKER_EVICT_STRATEGY_CLASS, GreedyEvictor.class.getName());%0A
     Evictor evic
@@ -2230,32 +2230,33 @@
 victor = Evictor
+.
 Factory.create(E
@@ -2257,27 +2257,20 @@
 eate
-(
 Evictor
-Type.GREEDY
+(conf
 , sB
@@ -2348,34 +2348,32 @@
 dyEvictor);%0A  %7D%0A
-  
 %0A  @Test%0A  publi
@@ -2398,32 +2398,155 @@
 locatorTest() %7B%0A
+    TachyonConf conf = new TachyonConf();%0A    conf.set(Constants.WORKER_EVICT_STRATEGY_CLASS, LRUEvictor.class.getName());%0A
     Evictor evic
@@ -2550,32 +2550,33 @@
 victor = Evictor
+.
 Factory.create(E
@@ -2577,24 +2577,20 @@
 eate
-(
 Evictor
-Type.LRU
+(conf
 , sB
@@ -2673,18 +2673,16 @@
 r);%0A  %7D%0A
-  
 %0A  @Test
@@ -2723,24 +2723,66 @@
 torTest() %7B%0A
+    TachyonConf conf = new TachyonConf();%0A
     Evictor 
@@ -2794,24 +2794,25 @@
 or = Evictor
+.
 Factory.crea
@@ -2817,28 +2817,20 @@
 eate
-(
 Evictor
-Type.DEFAULT
+(conf
 , sB

Fix unit test of EvictorFactory