Index: src/test/org/apache/hadoop/hbase/TestScannerWhileMemcacheFlush.java =================================================================== --- src/test/org/apache/hadoop/hbase/TestScannerWhileMemcacheFlush.java (revision 0) +++ src/test/org/apache/hadoop/hbase/TestScannerWhileMemcacheFlush.java (revision 0) @@ -0,0 +1,103 @@ +/** + * Copyright 2008 The Apache Software Foundation + * + * Licensed to the Apache Software Foundation (ASF) 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 org.apache.hadoop.hbase; + +import java.io.IOException; + +import junit.framework.Assert; + +import org.apache.hadoop.hbase.HBaseClusterTestCase; +import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.client.HBaseAdmin; +import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.client.Scanner; +import org.apache.hadoop.hbase.io.BatchUpdate; +import org.apache.hadoop.hbase.io.RowResult; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.log4j.Logger; + +public class TestScannerWhileMemcacheFlush extends HBaseClusterTestCase { + + static final Logger LOG = + Logger.getLogger(TestScannerWhileMemcacheFlush.class.getName()); + + + private static final String TABLE_NAME = "table"; + + private static final byte[] FAMILY = Bytes.toBytes("family:"); + private static final byte[] COL_A = Bytes.toBytes("family:a"); + + private static final int NUM_ROWS = 1000; + private static final int NUM_SCANS = 100; + + private HBaseAdmin admin; + private HTable table; + + /** constructor */ + public TestScannerWhileMemcacheFlush() { + conf.setInt("hbase.regionserver.optionalcacheflushinterval", 10000); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + HTableDescriptor desc = new HTableDescriptor(TABLE_NAME); + desc.addFamily(new HColumnDescriptor(FAMILY)); + admin = new HBaseAdmin(conf); + admin.createTable(desc); + table = new HTable(conf, desc.getName()); + + writeInitalRows(); + } + + private void writeInitalRows() throws IOException { + for (int i = 0; i < NUM_ROWS; i++) { + BatchUpdate update = new BatchUpdate(Bytes.toBytes("row" + i)); + update.put(COL_A, Bytes.toBytes(i)); + table.commit(update); + } + } + + public void testScanWhileFlush() throws IOException { + + for (int i=0; i < NUM_SCANS; i++) { + Scanner scanner = table.getScanner(new byte [][] {COL_A}); + LOG.info("got scanner"); + + RowResult result = scanner.next(); + int numFound = 0; + while (result != null) { + if (!result.containsKey(COL_A)) { + LOG.warn("Failing Assert"); + } + Assert.assertTrue(result.containsKey(COL_A)); + numFound++; + result = scanner.next(); + } + if (NUM_ROWS != numFound) { + LOG.warn("Failing assert"); + } + Assert.assertEquals(NUM_ROWS, numFound); + } + } + +}