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;
022import org.apache.hadoop.hbase.regionserver.HStoreFile;
023
024/**
025 * Class to create list of mock storefiles of specified length. This is great for testing edge
026 * cases.
027 */
028class ExplicitFileListGenerator extends StoreFileListGenerator {
029
030  /** The explicit files size lists to return. */
031  private int[][] fileSizes =
032    new int[][] { { 1000, 350, 200, 100, 20, 10, 10 }, { 1000, 450, 200, 100, 20, 10, 10 },
033      { 1000, 550, 200, 100, 20, 10, 10 }, { 1000, 650, 200, 100, 20, 10, 10 },
034      { 1, 1, 600, 1, 1, 1, 1 }, { 1, 1, 600, 600, 600, 600, 600, 1, 1, 1, 1 },
035      { 1, 1, 600, 600, 600, 1, 1, 1, 1 }, { 1000, 250, 25, 25, 25, 25, 25, 25 },
036      { 25, 25, 25, 25, 25, 25, 500 }, { 1000, 1000, 1000, 1000, 900 }, { 107, 50, 10, 10, 10, 10 },
037      { 2000, 107, 50, 10, 10, 10, 10 }, { 9, 8, 7, 6, 5, 4, 3, 2, 1 },
038      { 11, 18, 9, 8, 7, 6, 5, 4, 3, 2, 1 }, { 110, 18, 18, 18, 18, 9, 8, 7, 6, 5, 4, 3, 2, 1 },
039      { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15 } };
040
041  @Override
042  public final Iterator<List<HStoreFile>> iterator() {
043    return new Iterator<List<HStoreFile>>() {
044      private int nextIndex = 0;
045
046      @Override
047      public boolean hasNext() {
048        return nextIndex < fileSizes.length;
049      }
050
051      @Override
052      public List<HStoreFile> next() {
053        List<HStoreFile> files = createStoreFileList(fileSizes[nextIndex]);
054        nextIndex += 1;
055        return files;
056      }
057
058      @Override
059      public void remove() {
060      }
061    };
062  }
063
064}