<commit_before>/*
 * Copyright (C) 2013 The Calrissian Authors
 *
 * 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 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.calrissian.accumulorecipes.rangestore.impl;


import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.mock.MockInstance;
import org.apache.accumulo.core.security.Authorizations;
import org.calrissian.accumulorecipes.rangestore.helper.LongRangeHelper;
import org.calrissian.mango.domain.ValueRange;
import org.junit.Test;

import java.util.List;

import static com.google.common.collect.Lists.newArrayList;
import static java.util.Arrays.asList;
import static java.util.Collections.singleton;
import static org.junit.Assert.assertEquals;

public class AccumuloRangeStoreTest {

    public static Connector getConnector() throws AccumuloSecurityException, AccumuloException {
        return new MockInstance().getConnector("root", "".getBytes());
    }

    private static void compareRanges(ValueRange<Long> expected, ValueRange<Long> actual) {

        assertEquals(expected.getStart(), actual.getStart());
        assertEquals(expected.getStop(), actual.getStop());
    }

    @Test
    public void testSaveAndQuery() throws Exception {
        AccumuloRangeStore<Long> rangeStore = new AccumuloRangeStore<Long>(getConnector(), new LongRangeHelper());
        ValueRange<Long> testData = new ValueRange<Long>(0L, 10L);
        rangeStore.save(singleton(testData));

        List<ValueRange<Long>> results = newArrayList(rangeStore.query(new ValueRange<Long>(0L, Long.MAX_VALUE), new Authorizations()));

        assertEquals(1, results.size());
        compareRanges(testData, results.get(0));
    }

    @Test
    public void testQuerySingleRangeExpected() throws Exception {
        AccumuloRangeStore<Long> rangeStore = new AccumuloRangeStore<Long>(getConnector(), new LongRangeHelper());

        rangeStore.save(singleton(new ValueRange<Long>(1L, 4L)));
        rangeStore.save(singleton(new ValueRange<Long>(3L, 7L)));
        rangeStore.save(singleton(new ValueRange<Long>(8L, 9L)));
<commit_msg>Found error in range store.  Included an ignore test to highlight a test case.<commit_after>/*
 * Copyright (C) 2013 The Calrissian Authors
 *
 * 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 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.calrissian.accumulorecipes.rangestore.impl;


import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.mock.MockInstance;
import org.apache.accumulo.core.security.Authorizations;
import org.calrissian.accumulorecipes.rangestore.helper.LongRangeHelper;
import org.calrissian.mango.domain.ValueRange;
import org.junit.Ignore;
import org.junit.Test;

import java.util.List;

import static com.google.common.collect.Lists.newArrayList;
import static java.util.Arrays.asList;
import static java.util.Collections.singleton;
import static org.junit.Assert.assertEquals;

public class AccumuloRangeStoreTest {

    public static Connector getConnector() throws AccumuloSecurityException, AccumuloException {
        return new MockInstance().getConnector("root", "".getBytes());
    }

    private static void compareRanges(ValueRange<Long> expected, ValueRange<Long> actual) {

        assertEquals(expected.getStart(), actual.getStart());
        assertEquals(expected.getStop(), actual.getStop());
    }

    @Ignore
    @Test
    public void testGoofyMonsterRange() throws Exception{
        AccumuloRangeStore<Long> rangeStore = new AccumuloRangeStore<Long>(getConnector(), new LongRangeHelper());

        rangeStore.save(singleton(new ValueRange<Long>(5L, 10L)));
        rangeStore.save(singleton(new ValueRange<Long>(90L, 95L)));
        rangeStore.save(singleton(new ValueRange<Long>(2L, 98L)));
        rangeStore.save(singleton(new ValueRange<Long>(20L, 80L)));

        //should return [2-98] and [20-80]
        List<ValueRange<Long>> results = newArrayList(rangeStore.query(new ValueRange<Long>(49L, 51L), new Authorizations()));

        //actually returns [20-80], [2-98], [20-80] because the forward and monster iterator both pick up 20-80
        assertEquals(2, results.size());
        compareRanges(new ValueRange<Long>(1L, 4L), results.get(0));
    }

    @Test
    public void testSaveAndQuery() throws Exception {
        AccumuloRangeStore<Long> rangeStore = new AccumuloRangeStore<Long>(getConnector(), new LongRangeHelper());
        ValueRange<Long> testData = new ValueRange<Long>(0L, 10L);
        rangeStore.save(singleton(testData));

        List<ValueRange<Long>> results = newArrayList(rangeStore.query(new ValueRange<Long>(0L, Long.MAX_VALUE), new Authorizations()));

        assertEquals(1, results.size());
        compareRanges(testData, results.get(0));
    }

    @Test
    public void testQuerySingleRangeExpected() throws Exception {
        AccumuloRangeStore<Long> rangeStore = new AccumuloRangeStore<Long>(getConnector(), new LongRangeHelper());

        rangeStore.save(singleton(new ValueRange<Long>(1L, 4L)));
        rangeStore.save(singleton(new ValueRange<Long>(3L, 7L)));
        rangeStore.save(singleton(new ValueRange<Long>(8L, 9L)));

{'fraction_non_alphanumeric': 0.10937746256895194, 'fraction_numerical': 0.013238770685579196, 'mean_word_length': 4.571553994732222, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2567778', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1780, 'n_words': 457}