Search in sources :

Example 36 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.

the class VisibilityConstraintTest method setUp.

@Before
public void setUp() throws Exception {
    vc = new VisibilityConstraint();
    mutation = new Mutation("r");
    ArrayByteSequence bs = new ArrayByteSequence("good".getBytes(UTF_8));
    AuthorizationContainer ac = createNiceMock(AuthorizationContainer.class);
    expect(ac.contains(bs)).andReturn(true);
    replay(ac);
    env = createMock(Environment.class);
    expect(env.getAuthorizationsContainer()).andReturn(ac);
    replay(env);
}
Also used : VisibilityConstraint(org.apache.accumulo.core.constraints.VisibilityConstraint) Environment(org.apache.accumulo.core.constraints.Constraint.Environment) Mutation(org.apache.accumulo.core.data.Mutation) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Before(org.junit.Before)

Example 37 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.

the class VisibilityEvaluatorTest method testUnescape.

@Test
public void testUnescape() {
    assertEquals("a\"b", VisibilityEvaluator.unescape(new ArrayByteSequence("a\\\"b")).toString());
    assertEquals("a\\b", VisibilityEvaluator.unescape(new ArrayByteSequence("a\\\\b")).toString());
    assertEquals("a\\\"b", VisibilityEvaluator.unescape(new ArrayByteSequence("a\\\\\\\"b")).toString());
    assertEquals("\\\"", VisibilityEvaluator.unescape(new ArrayByteSequence("\\\\\\\"")).toString());
    assertEquals("a\\b\\c\\d", VisibilityEvaluator.unescape(new ArrayByteSequence("a\\\\b\\\\c\\\\d")).toString());
    try {
        VisibilityEvaluator.unescape(new ArrayByteSequence("a\\b"));
        fail("Expected failure to unescape invalid escape sequence");
    } catch (IllegalArgumentException e) {
    }
    try {
        VisibilityEvaluator.unescape(new ArrayByteSequence("a\\b\\c"));
        fail("Expected failure to unescape invalid escape sequence");
    } catch (IllegalArgumentException e) {
    }
    try {
        VisibilityEvaluator.unescape(new ArrayByteSequence("a\"b\\"));
        fail("Expected failure to unescape invalid escape sequence");
    } catch (IllegalArgumentException e) {
    }
}
Also used : ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Test(org.junit.Test)

Example 38 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.

the class ColumnFamilySkippingIteratorTest method test3.

public void test3() throws Exception {
    // construct test where ColumnFamilySkippingIterator might try to seek past the end of the user supplied range
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    for (int r = 0; r < 3; r++) {
        for (int cf = 4; cf < 1000; cf++) {
            for (int cq = 0; cq < 1; cq++) {
                put(tm1, r, cf, cq, 6, r * cf * cq);
            }
        }
    }
    CountingIterator ci = new CountingIterator(new SortedMapIterator(tm1));
    ColumnFamilySkippingIterator cfi = new ColumnFamilySkippingIterator(ci);
    HashSet<ByteSequence> colfams = new HashSet<>();
    colfams.add(new ArrayByteSequence(String.format("%06d", 4)));
    Range range = new Range(newKey(0, 4, 0, 6), true, newKey(0, 400, 0, 6), true);
    cfi.seek(range, colfams, true);
    assertTrue(cfi.hasTop());
    assertEquals(newKey(0, 4, 0, 6), cfi.getTopKey());
    cfi.next();
    assertFalse(cfi.hasTop());
    colfams.add(new ArrayByteSequence(String.format("%06d", 500)));
    cfi.seek(range, colfams, true);
    assertTrue(cfi.hasTop());
    assertEquals(newKey(0, 4, 0, 6), cfi.getTopKey());
    cfi.next();
    assertFalse(cfi.hasTop());
    range = new Range(newKey(0, 4, 0, 6), true, newKey(1, 400, 0, 6), true);
    cfi.seek(range, colfams, true);
    assertTrue(cfi.hasTop());
    assertEquals(newKey(0, 4, 0, 6), cfi.getTopKey());
    cfi.next();
    assertTrue(cfi.hasTop());
    assertEquals(newKey(0, 500, 0, 6), cfi.getTopKey());
    cfi.next();
    assertTrue(cfi.hasTop());
    assertEquals(newKey(1, 4, 0, 6), cfi.getTopKey());
    cfi.next();
    assertFalse(cfi.hasTop());
// System.out.println(ci.getCount());
}
Also used : TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Value(org.apache.accumulo.core.data.Value) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Key(org.apache.accumulo.core.data.Key) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) HashSet(java.util.HashSet)

Example 39 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.

the class ColumnFamilySkippingIteratorTest method test2.

public void test2() throws Exception {
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    for (int r = 0; r < 10; r++) {
        for (int cf = 0; cf < 1000; cf++) {
            for (int cq = 0; cq < 3; cq++) {
                put(tm1, r, cf, cq, 6, r * cf * cq);
            }
        }
    }
    HashSet<ByteSequence> allColfams = new HashSet<>();
    for (int cf = 0; cf < 1000; cf++) {
        allColfams.add(new ArrayByteSequence(String.format("%06d", cf)));
    }
    ColumnFamilySkippingIterator cfi = new ColumnFamilySkippingIterator(new SortedMapIterator(tm1));
    HashSet<ByteSequence> colfams = new HashSet<>();
    runTest(cfi, 30000, 0, allColfams, colfams);
    colfams.add(new ArrayByteSequence(String.format("%06d", 60)));
    runTest(cfi, 30000, 30, allColfams, colfams);
    colfams.add(new ArrayByteSequence(String.format("%06d", 602)));
    runTest(cfi, 30000, 60, allColfams, colfams);
    colfams.add(new ArrayByteSequence(String.format("%06d", 0)));
    runTest(cfi, 30000, 90, allColfams, colfams);
    colfams.add(new ArrayByteSequence(String.format("%06d", 999)));
    runTest(cfi, 30000, 120, allColfams, colfams);
    colfams.remove(new ArrayByteSequence(String.format("%06d", 0)));
    runTest(cfi, 30000, 90, allColfams, colfams);
    colfams.add(new ArrayByteSequence(String.format("%06d", 1000)));
    runTest(cfi, 30000, 90, allColfams, colfams);
    colfams.remove(new ArrayByteSequence(String.format("%06d", 999)));
    runTest(cfi, 30000, 60, allColfams, colfams);
    colfams.add(new ArrayByteSequence(String.format("%06d", 61)));
    runTest(cfi, 30000, 90, allColfams, colfams);
    for (int i = 62; i < 100; i++) colfams.add(new ArrayByteSequence(String.format("%06d", i)));
    runTest(cfi, 30000, 1230, allColfams, colfams);
}
Also used : Value(org.apache.accumulo.core.data.Value) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Key(org.apache.accumulo.core.data.Key) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) HashSet(java.util.HashSet)

Aggregations

ArrayByteSequence (org.apache.accumulo.core.data.ArrayByteSequence)39 ByteSequence (org.apache.accumulo.core.data.ByteSequence)26 HashSet (java.util.HashSet)20 Test (org.junit.Test)18 Key (org.apache.accumulo.core.data.Key)10 Value (org.apache.accumulo.core.data.Value)9 Range (org.apache.accumulo.core.data.Range)8 ArrayList (java.util.ArrayList)7 TreeMap (java.util.TreeMap)6 SortedMapIterator (org.apache.accumulo.core.iterators.SortedMapIterator)5 Text (org.apache.hadoop.io.Text)5 HashMap (java.util.HashMap)4 ColumnFamilySkippingIterator (org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Scanner (org.apache.accumulo.core.client.Scanner)2 Mutation (org.apache.accumulo.core.data.Mutation)2 PartialKey (org.apache.accumulo.core.data.PartialKey)2 IterInfo (org.apache.accumulo.core.data.thrift.IterInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1