Search in sources :

Example 21 with Value

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

the class CorpusChunkTest method testMightContainLocatorKeyValueReproA.

@Test
public void testMightContainLocatorKeyValueReproA() {
    Value value = null;
    Text term = null;
    int position = 0;
    while (term == null) {
        value = Value.wrap(Convert.javaToThrift("l  z15zses"));
        position = 0;
        for (String string : value.getObject().toString().split(TStrings.REGEX_GROUP_OF_ONE_OR_MORE_WHITESPACE_CHARS)) {
            if (!GlobalState.STOPWORDS.contains(string) && !Strings.isNullOrEmpty(string)) {
                term = Text.wrap(string);
                break;
            } else {
                position++;
                continue;
            }
        }
    }
    doTestMightContainLocatorKeyValue(getLocator(), value, term, getRecord(), position);
}
Also used : Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text) Test(org.junit.Test)

Example 22 with Value

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

the class Write method fromByteBuffer.

/**
 * Return the Write encoded in {@code bytes} so long as those bytes adhere
 * to the format specified by the {@link #getBytes()} method. This method
 * assumes that all the bytes in the {@code bytes} belong to the Value. In
 * general, it is necessary to get the appropriate Write slice from the
 * parent ByteBuffer using {@link ByteBuffers#slice(ByteBuffer, int, int)}.
 *
 * @param bytes
 * @return the Value
 */
public static Write fromByteBuffer(ByteBuffer bytes) {
    int keySize = bytes.getInt();
    Action type = Action.values()[bytes.get()];
    long version = bytes.getLong();
    Identifier record = Identifier.fromByteBuffer(ByteBuffers.get(bytes, Identifier.SIZE));
    Text key = Text.fromByteBuffer(ByteBuffers.get(bytes, keySize));
    Value value = Value.fromByteBuffer(ByteBuffers.get(bytes, bytes.remaining()));
    return new Write(type, key, value, record, version);
}
Also used : Action(com.cinchapi.concourse.server.storage.Action) Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text)

Example 23 with Value

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

the class RangeLockServiceTest method testWriteLtLowerValueIsNotRangeBlockedIfReadingBw.

@Test
public void testWriteLtLowerValueIsNotRangeBlockedIfReadingBw() throws InterruptedException {
    final Text key = Variables.register("key", TestData.getText());
    final Value value1 = Variables.register("value1", TestData.getValue());
    final Value value2 = Variables.register("value2", increase(value1));
    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch finishLatch = new CountDownLatch(1);
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            rangeLockService.getReadLock(key, Operator.BETWEEN, value1, value2).lock();
            startLatch.countDown();
            try {
                finishLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            rangeLockService.getReadLock(key, Operator.BETWEEN, value1, value2).unlock();
        }
    });
    t.start();
    startLatch.await();
    Value value3 = Variables.register("value3", decrease(value1));
    Assert.assertFalse(rangeLockService.isRangeBlocked(LockType.WRITE, RangeToken.forReading(key, null, value3)));
    finishLatch.countDown();
}
Also used : Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest)

Example 24 with Value

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

the class IndexRecordTest method testFindBrowseOnlyReturnsRelevantData.

@Test
public void testFindBrowseOnlyReturnsRelevantData() {
    Text locator = TestData.getText();
    record = getRecord(locator);
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j <= i; j++) {
            record.append(getRevision(locator, Value.wrap(Convert.javaToThrift(j)), Identifier.of(i)));
        }
    }
    Map<Identifier, Set<Value>> data = ((IndexRecord) record).findAndGet(Operator.GREATER_THAN, Value.wrap(Convert.javaToThrift(50)));
    for (int i = 0; i < 100; i++) {
        Identifier pk = Identifier.of(i);
        if (i > 50) {
            Assert.assertTrue(data.containsKey(pk));
            Assert.assertEquals(i - 50, data.get(pk).size());
            for (Value value : data.get(pk)) {
                Assert.assertTrue(value.compareTo(Value.wrap(Convert.javaToThrift(50))) > 0);
            }
        } else {
            Assert.assertFalse(data.containsKey(pk));
        }
    }
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) Set(java.util.Set) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text) Test(org.junit.Test)

Example 25 with Value

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

the class TableRecordTest method testChronologize.

@Test
public void testChronologize() {
    Map<Long, Set<Value>> map = Maps.newLinkedHashMap();
    Set<Value> set = Sets.newLinkedHashSet();
    Set<Value> allValues = Sets.newLinkedHashSet();
    long recordId = TestData.getLong();
    Identifier primaryKey = Identifier.of(recordId);
    TableRecord record = TableRecord.create(primaryKey);
    for (long i = 30; i <= 35; i++) {
        Value value = null;
        while (value == null || !allValues.add(value)) {
            value = TestData.getValue();
        }
        record.append(getRevision(primaryKey, Text.wrapCached("name"), value));
        set.add(value);
    }
    long start = Time.now();
    for (long i = 36; i <= 45; i++) {
        set = Sets.newLinkedHashSet(set);
        Value value = null;
        while (value == null || !allValues.add(value)) {
            value = TestData.getValue();
        }
        record.append(getRevision(primaryKey, Text.wrapCached("name"), value));
        set.add(value);
        map.put(i, set);
    }
    long end = Time.now();
    for (long i = 51; i <= 60; i++) {
        Value value = null;
        while (value == null || !allValues.add(value)) {
            value = TestData.getValue();
        }
        record.append(getRevision(primaryKey, Text.wrapCached("name"), value));
    }
    Map<Long, Set<Value>> newMap = record.chronologize(Text.wrapCached("name"), start, end);
    long key = 36;
    for (Entry<Long, Set<Value>> e : newMap.entrySet()) {
        Set<Value> result = e.getValue();
        Assert.assertEquals(map.get(key), result);
        key++;
    }
}
Also used : Set(java.util.Set) Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value) Test(org.junit.Test)

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