Search in sources :

Example 11 with ILSMDiskComponentId

use of org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId in project asterixdb by apache.

the class CorrelatedPrefixMergePolicyTest method mockIndex.

private IndexInfo mockIndex(boolean isPrimary, List<ILSMDiskComponentId> componentIDs, List<ILSMDiskComponentId> resultComponentIDs, int partition) throws HyracksDataException {
    List<ILSMDiskComponent> components = new ArrayList<>();
    for (ILSMDiskComponentId id : componentIDs) {
        ILSMDiskComponent component = Mockito.mock(ILSMDiskComponent.class);
        Mockito.when(component.getComponentId()).thenReturn(id);
        Mockito.when(component.getComponentSize()).thenReturn(DEFAULT_COMPONENT_SIZE);
        Mockito.when(component.getState()).thenReturn(ComponentState.READABLE_UNWRITABLE);
        components.add(component);
    }
    ILSMIndex index = Mockito.mock(ILSMIndex.class);
    Mockito.when(index.getImmutableComponents()).thenReturn(components);
    ILSMIndexAccessor accessor = Mockito.mock(ILSMIndexAccessor.class);
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            List<ILSMDiskComponent> mergedComponents = invocation.getArgumentAt(1, List.class);
            mergedComponents.forEach(component -> {
                try {
                    resultComponentIDs.add(component.getComponentId());
                } catch (HyracksDataException e) {
                    e.printStackTrace();
                }
            });
            return null;
        }
    }).when(accessor).scheduleMerge(Mockito.any(ILSMIOOperationCallback.class), Mockito.anyListOf(ILSMDiskComponent.class));
    Mockito.when(index.createAccessor(Mockito.any(IModificationOperationCallback.class), Mockito.any(ISearchOperationCallback.class))).thenReturn(accessor);
    Mockito.when(index.isPrimaryIndex()).thenReturn(isPrimary);
    return new IndexInfo(index, DATASET_ID, 0, partition);
}
Also used : Arrays(java.util.Arrays) CorrelatedPrefixMergePolicyFactory(org.apache.asterix.common.context.CorrelatedPrefixMergePolicyFactory) ISearchOperationCallback(org.apache.hyracks.storage.common.ISearchOperationCallback) LSMDiskComponentId(org.apache.hyracks.storage.am.lsm.common.impls.LSMDiskComponentId) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ILSMDiskComponentId(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CorrelatedPrefixMergePolicy(org.apache.asterix.common.context.CorrelatedPrefixMergePolicy) Map(java.util.Map) TestCase(junit.framework.TestCase) DatasetInfo(org.apache.asterix.common.context.DatasetInfo) IndexInfo(org.apache.asterix.common.context.IndexInfo) IDatasetLifecycleManager(org.apache.asterix.common.api.IDatasetLifecycleManager) ILSMDiskComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent) ILSMIOOperationCallback(org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperationCallback) Set(java.util.Set) Test(org.junit.Test) ComponentState(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent.ComponentState) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) Mockito(org.mockito.Mockito) List(java.util.List) IModificationOperationCallback(org.apache.hyracks.storage.common.IModificationOperationCallback) ILSMMergePolicy(org.apache.hyracks.storage.am.lsm.common.api.ILSMMergePolicy) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) Assert(org.junit.Assert) ILSMDiskComponentId(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId) ArrayList(java.util.ArrayList) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) ISearchOperationCallback(org.apache.hyracks.storage.common.ISearchOperationCallback) IndexInfo(org.apache.asterix.common.context.IndexInfo) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IModificationOperationCallback(org.apache.hyracks.storage.common.IModificationOperationCallback) ILSMDiskComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ILSMIOOperationCallback(org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperationCallback) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ILSMDiskComponentId (org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId)11 ArrayList (java.util.ArrayList)9 LSMDiskComponentId (org.apache.hyracks.storage.am.lsm.common.impls.LSMDiskComponentId)8 IndexInfo (org.apache.asterix.common.context.IndexInfo)7 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)7 ILSMMergePolicy (org.apache.hyracks.storage.am.lsm.common.api.ILSMMergePolicy)7 Test (org.junit.Test)7 ILSMDiskComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent)4 ILSMComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent)2 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)2 ILSMIndexAccessor (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)2 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TestCase (junit.framework.TestCase)1 IDatasetLifecycleManager (org.apache.asterix.common.api.IDatasetLifecycleManager)1 CorrelatedPrefixMergePolicy (org.apache.asterix.common.context.CorrelatedPrefixMergePolicy)1