Skip to content

Commit

Permalink
task/unsafe_primitives_reading added headers, refactored test
Browse files Browse the repository at this point in the history
  • Loading branch information
ak0rz committed Mar 11, 2019
1 parent b4b2846 commit 26822ce
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 36 deletions.
91 changes: 55 additions & 36 deletions core/src/test/java/com/yandex/yoctodb/FoldedIndexTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* (C) YANDEX LLC, 2014-2019
*
* The Source Code called "YoctoDB" available at
* https://github.com/yandex/yoctodb is subject to the terms of the
* Mozilla Public License, v. 2.0 (hereinafter referred to as the "License").
*
* A copy of the License is also available at http://mozilla.org/MPL/2.0/.
*/

package com.yandex.yoctodb;

import com.yandex.yoctodb.immutable.Database;
Expand All @@ -21,6 +31,13 @@
*/
public class FoldedIndexTest {

String BYTE_FIELD_NAME = "byte";
String SHORT_FIELD_NAME = "short";
String INT_FIELD_NAME = "int";
String LONG_FIELD_NAME = "long";
String CHAR_FIELD_NAME = "char";
String STATE_FIELD_NAME = "state";

@Test
public void buildDatabase() throws IOException {
final DatabaseBuilder dbBuilder =
Expand All @@ -31,34 +48,36 @@ public void buildDatabase() throws IOException {
DatabaseFormat
.getCurrent()
.newDocumentBuilder()
.withField("state", "NEW", STORED)
.withField("byte", (byte) 1, STORED)
.withField("short", (short) 1, STORED)
.withField("int", 1, STORED)
.withField("long", 1L, STORED)
.withField("char", 'a', STORED)
.withField(STATE_FIELD_NAME, "NEW", STORED)
.withField(BYTE_FIELD_NAME, (byte) 1, STORED)
.withField(SHORT_FIELD_NAME, (short) 1, STORED)
.withField(INT_FIELD_NAME, 1, STORED)
.withField(LONG_FIELD_NAME, 1L, STORED)
.withField(CHAR_FIELD_NAME, 'a', STORED)
);
// Document 2
dbBuilder.merge(
DatabaseFormat
.getCurrent()
.newDocumentBuilder()
.withField("state", "USED", STORED)
.withField("byte", (byte) 2, STORED)
.withField("short", (short) 2, STORED)
.withField("int", 2, STORED)
.withField("long", 2L, STORED)
.withField("char", 'b', STORED)
.withField(STATE_FIELD_NAME, "USED", STORED)
.withField(BYTE_FIELD_NAME, (byte) 2, STORED)
.withField(SHORT_FIELD_NAME, (short) 2, STORED)
.withField(INT_FIELD_NAME, 2, STORED)
.withField(LONG_FIELD_NAME, 2L, STORED)
.withField(CHAR_FIELD_NAME, 'b', STORED)
);
// Document 3
dbBuilder.merge(
DatabaseFormat
.getCurrent()
.newDocumentBuilder()
.withField("state", "NEW", STORED)
.withField("byte", (byte) 1, STORED)
.withField("short", (short) 1, STORED)
.withField("int", 1, STORED)
.withField("long", 1L, STORED)
.withField("char", 'a', STORED)
.withField(STATE_FIELD_NAME, "NEW", STORED)
.withField(BYTE_FIELD_NAME, (byte) 1, STORED)
.withField(SHORT_FIELD_NAME, (short) 1, STORED)
.withField(INT_FIELD_NAME, 1, STORED)
.withField(LONG_FIELD_NAME, 1L, STORED)
.withField(CHAR_FIELD_NAME, 'a', STORED)
);

final ByteArrayOutputStream os = new ByteArrayOutputStream();
Expand All @@ -69,29 +88,29 @@ public void buildDatabase() throws IOException {
.getDatabaseReader()
.from(Buffer.from(os.toByteArray()));

assertEquals("NEW", getValueFromBuffer(db.getFieldValue(0, "state")));
assertEquals("USED", getValueFromBuffer(db.getFieldValue(1, "state")));
assertEquals("NEW", getValueFromBuffer(db.getFieldValue(2, "state")));
assertEquals("NEW", getValueFromBuffer(db.getFieldValue(0, STATE_FIELD_NAME)));
assertEquals("USED", getValueFromBuffer(db.getFieldValue(1, STATE_FIELD_NAME)));
assertEquals("NEW", getValueFromBuffer(db.getFieldValue(2, STATE_FIELD_NAME)));

assertEquals((byte) 1, db.getByteValue(0, "byte"));
assertEquals((byte) 2, db.getByteValue(1, "byte"));
assertEquals((byte) 1, db.getByteValue(2, "byte"));
assertEquals((byte) 1, db.getByteValue(0, BYTE_FIELD_NAME));
assertEquals((byte) 2, db.getByteValue(1, BYTE_FIELD_NAME));
assertEquals((byte) 1, db.getByteValue(2, BYTE_FIELD_NAME));

assertEquals((short) 1, db.getShortValue(0, "short"));
assertEquals((short) 2, db.getShortValue(1, "short"));
assertEquals((short) 1, db.getShortValue(2, "short"));
assertEquals((short) 1, db.getShortValue(0, SHORT_FIELD_NAME));
assertEquals((short) 2, db.getShortValue(1, SHORT_FIELD_NAME));
assertEquals((short) 1, db.getShortValue(2, SHORT_FIELD_NAME));

assertEquals(1, db.getIntValue(0, "int"));
assertEquals(2, db.getIntValue(1, "int"));
assertEquals(1, db.getIntValue(2, "int"));
assertEquals(1, db.getIntValue(0, INT_FIELD_NAME));
assertEquals(2, db.getIntValue(1, INT_FIELD_NAME));
assertEquals(1, db.getIntValue(2, INT_FIELD_NAME));

assertEquals(1L, db.getLongValue(0, "long"));
assertEquals(2L, db.getLongValue(1, "long"));
assertEquals(1L, db.getLongValue(2, "long"));
assertEquals(1L, db.getLongValue(0, LONG_FIELD_NAME));
assertEquals(2L, db.getLongValue(1, LONG_FIELD_NAME));
assertEquals(1L, db.getLongValue(2, LONG_FIELD_NAME));

assertEquals('a', db.getCharValue(0, "char"));
assertEquals('b', db.getCharValue(1, "char"));
assertEquals('a', db.getCharValue(2, "char"));
assertEquals('a', db.getCharValue(0, CHAR_FIELD_NAME));
assertEquals('b', db.getCharValue(1, CHAR_FIELD_NAME));
assertEquals('a', db.getCharValue(2, CHAR_FIELD_NAME));


}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* (C) YANDEX LLC, 2014-2019
*
* The Source Code called "YoctoDB" available at
* https://github.com/yandex/yoctodb is subject to the terms of the
* Mozilla Public License, v. 2.0 (hereinafter referred to as the "License").
*
* A copy of the License is also available at http://mozilla.org/MPL/2.0/.
*/

package com.yandex.yoctodb;

import com.yandex.yoctodb.immutable.Database;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* (C) YANDEX LLC, 2014-2016
*
* The Source Code called "YoctoDB" available at
* https://github.com/yandex/yoctodb is subject to the terms of the
* Mozilla Public License, v. 2.0 (hereinafter referred to as the "License").
*
* A copy of the License is also available at http://mozilla.org/MPL/2.0/.
*/

package com.yandex.yoctodb.util.immutable.impl;

import com.yandex.yoctodb.util.UnsignedByteArray;
Expand Down

0 comments on commit 26822ce

Please sign in to comment.