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));
}
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));
}
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);
}
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());
}
}
}
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));
}
Aggregations