Search in sources :

Example 66 with Value

use of com.cinchapi.concourse.server.model.Value in project concourse by cinchapi.

the class RangeTokensTest method testConvertLessThanOrEqualsRangeToken.

@Test
public void testConvertLessThanOrEqualsRangeToken() {
    Text key = TestData.getText();
    Operator operator = Operator.LESS_THAN_OR_EQUALS;
    Value value = TestData.getValue();
    RangeToken token = RangeToken.forReading(key, operator, value);
    Range<Value> range = Iterables.getOnlyElement(RangeTokens.convertToRange(token));
    Assert.assertEquals(range, Range.atMost(value));
}
Also used : Operator(com.cinchapi.concourse.thrift.Operator) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 67 with Value

use of com.cinchapi.concourse.server.model.Value in project concourse by cinchapi.

the class RangeTokensTest method testConvertWriteRangeToken.

@Test
public void testConvertWriteRangeToken() {
    Text key = TestData.getText();
    Value value = TestData.getValue();
    RangeToken token = RangeToken.forWriting(key, value);
    Range<Value> range = Iterables.getOnlyElement(RangeTokens.convertToRange(token));
    Assert.assertEquals(range, Range.singleton(value));
}
Also used : Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 68 with Value

use of com.cinchapi.concourse.server.model.Value in project concourse by cinchapi.

the class ByteableCollectionsTest method testStreamingIterator.

@Test
public void testStreamingIterator() {
    Path file = Paths.get(TestData.getTemporaryTestFile());
    List<Value> values = Lists.newArrayList();
    int count = TestData.getScaleCount();
    for (int i = 0; i < count; ++i) {
        values.add(TestData.getValue());
    }
    ByteBuffer bytes = ByteableCollections.toByteBuffer(values);
    FileSystem.writeBytes(bytes, file.toString());
    int bufferSize = TestData.getScaleCount();
    Iterator<ByteBuffer> it = ByteableCollections.stream(file, bufferSize);
    List<Value> newValues = Lists.newArrayList();
    while (it.hasNext()) {
        newValues.add(Value.fromByteBuffer(it.next()));
    }
    Assert.assertEquals(values, newValues);
}
Also used : Path(java.nio.file.Path) Value(com.cinchapi.concourse.server.model.Value) ByteBuffer(java.nio.ByteBuffer) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 69 with Value

use of com.cinchapi.concourse.server.model.Value in project concourse by cinchapi.

the class SegmentTest method testDataDeduplication.

@Test
public void testDataDeduplication() {
    String key = "name";
    TObject value = Convert.javaToThrift("Fonamey");
    long record = 1;
    // Simulate adding and removing while server is running, but creating
    // new intermediate TObjects
    Write w1 = Write.add(key, Convert.javaToThrift("Fonamey"), record);
    Write w2 = Write.remove(key, Convert.javaToThrift("Fonamey"), record);
    Assert.assertNotSame(w1.getValue(), w2.getValue());
    segment.acquire(w1);
    segment.acquire(w2);
    // Simulate loading data from disk and creating new intermediate because
    // values are not cached when read
    w1 = Write.fromByteBuffer(w1.getBytes());
    w2 = Write.fromByteBuffer(w2.getBytes());
    Assert.assertNotSame(w1.getValue(), w2.getValue());
    segment.acquire(w1);
    segment.acquire(w2);
    int count = TestData.getScaleCount();
    for (int i = 0; i < count; ++i) {
        Write write = Numbers.isEven(i) ? Write.remove(key, value, record) : Write.add(key, value, record);
        write = Write.fromByteBuffer(write.getBytes());
        segment.acquire(write);
    }
    Text name = null;
    Value fonamey = null;
    Identifier one = null;
    Position position = null;
    Iterator<Revision<Identifier, Text, Value>> tit = segment.table().iterator();
    while (tit.hasNext()) {
        Revision<Identifier, Text, Value> revision = tit.next();
        if (one == null) {
            one = revision.getLocator();
        }
        if (name == null) {
            name = revision.getKey();
        }
        if (fonamey == null) {
            fonamey = revision.getValue();
        }
        Assert.assertSame(one, revision.getLocator());
        Assert.assertSame(name, revision.getKey());
        Assert.assertSame(fonamey, revision.getValue());
    }
    Iterator<Revision<Text, Value, Identifier>> iit = segment.index().iterator();
    while (iit.hasNext()) {
        Revision<Text, Value, Identifier> revision = iit.next();
        if (one == null) {
            one = revision.getValue();
        }
        if (name == null) {
            name = revision.getLocator();
        }
        if (fonamey == null) {
            fonamey = revision.getKey();
        }
        Assert.assertSame(one, revision.getValue());
        Assert.assertSame(name, revision.getLocator());
        Assert.assertSame(fonamey, revision.getKey());
    }
    Iterator<Revision<Text, Text, Position>> cit = segment.corpus().iterator();
    while (cit.hasNext()) {
        Revision<Text, Text, Position> revision = cit.next();
        if (position == null) {
            position = revision.getValue();
        }
        if (name == null) {
            name = revision.getLocator();
        }
        Assert.assertSame(position, revision.getValue());
        Assert.assertSame(name, revision.getLocator());
        if (revision.getKey().toString().equals("name")) {
            Assert.assertSame(name, revision.getKey());
        }
    }
}
Also used : Write(com.cinchapi.concourse.server.storage.temp.Write) TObject(com.cinchapi.concourse.thrift.TObject) Position(com.cinchapi.concourse.server.model.Position) Text(com.cinchapi.concourse.server.model.Text) Identifier(com.cinchapi.concourse.server.model.Identifier) Revision(com.cinchapi.concourse.server.storage.db.Revision) Value(com.cinchapi.concourse.server.model.Value) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 70 with Value

use of com.cinchapi.concourse.server.model.Value in project concourse by cinchapi.

the class BufferedStoreTest method doTestFindBuffered.

/**
 * Execute the findBuffered test.
 *
 * @param data
 * @param d
 * @param operator
 */
private void doTestFindBuffered(List<Data> data, Data d, Operator operator) {
    Variables.register("d", d);
    Variables.register("operator", operator);
    Map<Long, Set<TObject>> rtv = Maps.newHashMap();
    Iterator<Data> it = data.iterator();
    while (it.hasNext()) {
        Data _d = it.next();
        if (_d.key.equals(d.key)) {
            // NOTE: It is necessaty to wrap the TObjects as Values because
            // TObject compareTo is not correctly defined.
            Value v1 = Value.wrap(d.value);
            Value v2 = Value.wrap(_d.value);
            boolean matches = false;
            if (operator == Operator.EQUALS) {
                matches = v1.equals(v2);
            } else if (operator == Operator.NOT_EQUALS) {
                matches = !v1.equals(v2);
            } else if (operator == Operator.GREATER_THAN) {
                matches = v1.compareTo(v2) < 0;
            } else if (operator == Operator.GREATER_THAN_OR_EQUALS) {
                matches = v1.compareTo(v2) <= 0;
            } else if (operator == Operator.LESS_THAN) {
                matches = v1.compareTo(v2) > 0;
            } else if (operator == Operator.LESS_THAN_OR_EQUALS) {
                matches = v1.compareTo(v2) >= 0;
            } else if (operator == Operator.BETWEEN) {
            // TODO Implement this later. We will need to get a a second
            // value from the list of data
            } else if (operator == Operator.REGEX) {
                matches = v2.toString().matches(v1.toString());
            } else if (operator == Operator.NOT_REGEX) {
                matches = !v2.toString().matches(v1.toString());
            } else {
                throw new UnsupportedOperationException();
            }
            if (matches) {
                Set<TObject> values = rtv.get(_d.record);
                if (values == null) {
                    values = Sets.newHashSet();
                    rtv.put(_d.record, values);
                }
                if (_d.type == Action.ADD) {
                    Assert.assertTrue(values.add(_d.value));
                } else {
                    Assert.assertTrue(values.remove(_d.value));
                }
            }
        }
    }
    Set<Long> records = Sets.newHashSet();
    Iterator<Long> it2 = rtv.keySet().iterator();
    while (it2.hasNext()) {
        long record = it2.next();
        if (!rtv.get(record).isEmpty()) {
            records.add(record);
        }
    }
    Assert.assertEquals(records, store.find(d.key, operator, d.value));
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject) Set(java.util.Set) TestData(com.cinchapi.concourse.util.TestData) Value(com.cinchapi.concourse.server.model.Value)

Aggregations

Value (com.cinchapi.concourse.server.model.Value)73 Text (com.cinchapi.concourse.server.model.Text)60 Test (org.junit.Test)43 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)34 Identifier (com.cinchapi.concourse.server.model.Identifier)25 CountDownLatch (java.util.concurrent.CountDownLatch)22 Set (java.util.Set)14 Operator (com.cinchapi.concourse.thrift.Operator)10 Action (com.cinchapi.concourse.server.storage.Action)6 Range (com.google.common.collect.Range)6 LinkedHashSet (java.util.LinkedHashSet)6 TObject (com.cinchapi.concourse.thrift.TObject)5 LazyTransformSet (com.cinchapi.common.collect.lazy.LazyTransformSet)3 RangeToken (com.cinchapi.concourse.server.concurrent.RangeToken)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 ByteBuffer (java.nio.ByteBuffer)3 Path (java.nio.file.Path)3 NavigableSet (java.util.NavigableSet)3 CoalescableTreeMap (com.cinchapi.common.collect.CoalescableTreeMap)2 Position (com.cinchapi.concourse.server.model.Position)2