| /* |
| * Copyright 2009-2010 by The Regents of the University of California |
| * Licensed 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 from |
| * |
| * 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 edu.uci.ics.hyracks.storage.am.lsm.btree; |
| |
| import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer; |
| import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference; |
| import edu.uci.ics.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer; |
| import edu.uci.ics.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer; |
| import edu.uci.ics.hyracks.storage.am.btree.OrderedIndexTestContext; |
| import edu.uci.ics.hyracks.storage.am.btree.OrderedIndexTestDriver; |
| import edu.uci.ics.hyracks.storage.am.btree.OrderedIndexTestUtils; |
| import edu.uci.ics.hyracks.storage.am.btree.frames.BTreeLeafFrameType; |
| import edu.uci.ics.hyracks.storage.am.config.AccessMethodTestsConfig; |
| import edu.uci.ics.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor; |
| import edu.uci.ics.hyracks.storage.am.lsm.common.impls.NoOpIOOperationCallback; |
| |
| @SuppressWarnings("rawtypes") |
| public abstract class LSMBTreeMergeTestDriver extends OrderedIndexTestDriver { |
| |
| private final OrderedIndexTestUtils orderedIndexTestUtils; |
| |
| public LSMBTreeMergeTestDriver(BTreeLeafFrameType[] leafFrameTypesToTest) { |
| super(leafFrameTypesToTest); |
| this.orderedIndexTestUtils = new OrderedIndexTestUtils(); |
| } |
| |
| @Override |
| protected void runTest(ISerializerDeserializer[] fieldSerdes, int numKeys, BTreeLeafFrameType leafType, |
| ITupleReference lowKey, ITupleReference highKey, ITupleReference prefixLowKey, ITupleReference prefixHighKey) |
| throws Exception { |
| OrderedIndexTestContext ctx = createTestContext(fieldSerdes, numKeys, leafType); |
| ctx.getIndex().create(); |
| ctx.getIndex().activate(); |
| // Start off with one tree bulk loaded. |
| // We assume all fieldSerdes are of the same type. Check the first one |
| // to determine which field types to generate. |
| if (fieldSerdes[0] instanceof IntegerSerializerDeserializer) { |
| orderedIndexTestUtils.bulkLoadIntTuples(ctx, numTuplesToInsert, getRandom()); |
| } else if (fieldSerdes[0] instanceof UTF8StringSerializerDeserializer) { |
| orderedIndexTestUtils.bulkLoadStringTuples(ctx, numTuplesToInsert, getRandom()); |
| } |
| |
| int maxTreesToMerge = AccessMethodTestsConfig.LSM_BTREE_MAX_TREES_TO_MERGE; |
| for (int i = 0; i < maxTreesToMerge; i++) { |
| for (int j = 0; j < i; j++) { |
| if (fieldSerdes[0] instanceof IntegerSerializerDeserializer) { |
| orderedIndexTestUtils.bulkLoadIntTuples(ctx, numTuplesToInsert, getRandom()); |
| } else if (fieldSerdes[0] instanceof UTF8StringSerializerDeserializer) { |
| orderedIndexTestUtils.bulkLoadStringTuples(ctx, numTuplesToInsert, getRandom()); |
| } |
| } |
| |
| ILSMIndexAccessor accessor = (ILSMIndexAccessor) ctx.getIndexAccessor(); |
| accessor.scheduleMerge(NoOpIOOperationCallback.INSTANCE); |
| |
| orderedIndexTestUtils.checkPointSearches(ctx); |
| orderedIndexTestUtils.checkScan(ctx); |
| orderedIndexTestUtils.checkDiskOrderScan(ctx); |
| orderedIndexTestUtils.checkRangeSearch(ctx, lowKey, highKey, true, true); |
| if (prefixLowKey != null && prefixHighKey != null) { |
| orderedIndexTestUtils.checkRangeSearch(ctx, prefixLowKey, prefixHighKey, true, true); |
| } |
| } |
| ctx.getIndex().deactivate(); |
| ctx.getIndex().destroy(); |
| } |
| |
| @Override |
| protected String getTestOpName() { |
| return "LSM Merge"; |
| } |
| } |