001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.regionserver.compactions;
019
020import java.util.Iterator;
021import java.util.List;
022
023import org.apache.hadoop.hbase.regionserver.HStoreFile;
024
025/**
026 * Class to create list of mock storefiles of specified length.
027 * This is great for testing edge cases.
028 */
029class ExplicitFileListGenerator extends StoreFileListGenerator {
030  /** The explicit files size lists to return. */
031  private int[][] fileSizes = new int[][]{
032      {1000, 350, 200, 100, 20, 10, 10},
033      {1000, 450, 200, 100, 20, 10, 10},
034      {1000, 550, 200, 100, 20, 10, 10},
035      {1000, 650, 200, 100, 20, 10, 10},
036      {1, 1, 600, 1, 1, 1, 1},
037      {1, 1, 600, 600, 600, 600, 600, 1, 1, 1, 1},
038      {1, 1, 600, 600, 600, 1, 1, 1, 1},
039      {1000, 250, 25, 25, 25, 25, 25, 25},
040      {25, 25, 25, 25, 25, 25, 500},
041      {1000, 1000, 1000, 1000, 900},
042      {107, 50, 10, 10, 10, 10},
043      {2000, 107, 50, 10, 10, 10, 10},
044      {9, 8, 7, 6, 5, 4, 3, 2, 1},
045      {11, 18, 9, 8, 7, 6, 5, 4, 3, 2, 1},
046      {110, 18, 18, 18, 18, 9, 8, 7, 6, 5, 4, 3, 2, 1},
047      {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15}
048  };
049
050  ExplicitFileListGenerator() {
051    super(ExplicitFileListGenerator.class);
052  }
053
054  @Override
055  public final Iterator<List<HStoreFile>> iterator() {
056    return new Iterator<List<HStoreFile>>() {
057      private int nextIndex = 0;
058      @Override
059      public boolean hasNext() {
060        return nextIndex < fileSizes.length;
061      }
062
063      @Override
064      public List<HStoreFile> next() {
065        List<HStoreFile> files =  createStoreFileList(fileSizes[nextIndex]);
066        nextIndex += 1;
067        return files;
068      }
069
070      @Override
071      public void remove() {
072      }
073    };
074  }
075}