use of org.apache.gora.examples.generated.WebPage in project gora by apache.
the class DataStoreTestUtil method assertEqualEmployeeObjects.
/**
* Simple function which iterates through a before (put) and after (get) object
* in an attempt to verify if the same field's and values have been obtained.
* Within the original employee object we iterate from 1 instead of 0 due to the
* removal of the '__g__' field at position 0 when we put objects into the datastore.
* This field is used to identify whether fields within the object, and
* consequently the object itself, are/is dirty however this field is not
* required when persisting the object.
* We explicitly get values from each field as this makes it easier to debug
* if tests go wrong.
* @param employee
* @param after
*/
private static void assertEqualEmployeeObjects(Employee employee, Employee after) {
//for (int i = 1; i < employee.SCHEMA$.getFields().size(); i++) {
// for (int j = 1; j < after.SCHEMA$.getFields().size(); j++) {
// assertEquals(employee.SCHEMA$.getFields().get(i), after.SCHEMA$.getFields().get(j));
// }
//}
//check name field
CharSequence beforeName = employee.getName();
CharSequence afterName = after.getName();
assertEquals(beforeName, afterName);
//check dateOfBirth field
Long beforeDOB = employee.getDateOfBirth();
Long afterDOB = after.getDateOfBirth();
assertEquals(beforeDOB, afterDOB);
//check ssn field
CharSequence beforeSsn = employee.getSsn();
CharSequence afterSsn = after.getSsn();
assertEquals(beforeSsn, afterSsn);
//check salary field
Integer beforeSalary = employee.getSalary();
Integer afterSalary = after.getSalary();
assertEquals(beforeSalary, afterSalary);
//check boss field
if (employee.getBoss() != null) {
if (employee.getBoss() instanceof Utf8) {
String beforeBoss = employee.getBoss().toString();
String afterBoss = after.getBoss().toString();
assertEquals("Boss String field values in UNION should be the same", beforeBoss, afterBoss);
} else {
Employee beforeBoss = (Employee) employee.getBoss();
Employee afterBoss = (Employee) after.getBoss();
assertEqualEmployeeObjects(beforeBoss, afterBoss);
}
}
//check webpage field
if (employee.getWebpage() != null) {
WebPage beforeWebPage = employee.getWebpage();
WebPage afterWebPage = after.getWebpage();
assertEqualWebPageObjects(beforeWebPage, afterWebPage);
}
}
use of org.apache.gora.examples.generated.WebPage in project gora by apache.
the class TestAvroStore method testQueryWebPages.
//AvroStore should be closed so that Hadoop file is completely flushed,
//so below test is copied and modified to close the store after pushing data
public static void testQueryWebPages(DataStore<String, WebPage> store) throws Exception {
Query<String, WebPage> query = store.newQuery();
Result<String, WebPage> result = query.execute();
int i = 0;
while (result.next()) {
WebPage page = result.get();
DataStoreTestUtil.assertWebPage(page, URL_INDEXES.get(page.getUrl().toString()));
i++;
}
assertEquals(i, URLS.length);
}
use of org.apache.gora.examples.generated.WebPage in project gora by apache.
the class TestMapFieldValueFilter method testSerialization.
@Test
public void testSerialization() throws IOException {
MapFieldValueFilter<String, WebPage> filter = new MapFieldValueFilter<>();
//set filter field name as metadata
filter.setFieldName(WebPage.Field.METADATA.toString());
filter.setMapKey(new Utf8("fetchTime"));
filter.setFilterOp(FilterOp.EQUALS);
filter.setFilterIfMissing(true);
filter.getOperands().add(new Utf8("http://example.org"));
byte[] byteArray = WritableUtils.toByteArray(filter);
MapFieldValueFilter<String, WebPage> filter2 = new MapFieldValueFilter<>();
filter2.readFields(new DataInputStream(new ByteArrayInputStream(byteArray)));
assertEquals(filter.getFieldName(), filter2.getFieldName());
assertEquals(filter.getMapKey(), filter2.getMapKey());
assertEquals(filter.getFilterOp(), filter2.getFilterOp());
assertArrayEquals(filter.getOperands().toArray(), filter2.getOperands().toArray());
assertEquals(filter.isFilterIfMissing(), filter2.isFilterIfMissing());
}
use of org.apache.gora.examples.generated.WebPage in project gora by apache.
the class TestMapFieldValueFilter method testFilterBasics.
@Test
public void testFilterBasics() {
MapFieldValueFilter<String, WebPage> filter = new MapFieldValueFilter<>();
//set filter field name as outlinks
filter.setFieldName(WebPage.Field.OUTLINKS.toString());
filter.setMapKey(new Utf8("example"));
filter.setFilterOp(FilterOp.EQUALS);
filter.setFilterIfMissing(true);
filter.getOperands().add(new Utf8("http://example.org"));
WebPage page = WebPage.newBuilder().build();
page.getOutlinks().put(new Utf8("example"), new Utf8("http://example.org"));
assertFalse(filter.filter("irrelevant", page));
page.getOutlinks().put(new Utf8("example"), new Utf8("http://example2.com"));
assertTrue(filter.filter("irrelevant", page));
page = new WebPage();
assertTrue(filter.filter("irrelevant", page));
filter.setFilterIfMissing(false);
assertFalse(filter.filter("irrelevant", page));
}
use of org.apache.gora.examples.generated.WebPage in project gora by apache.
the class TestMapFieldValueFilter method testFilterEntryInMap.
@Test
public void testFilterEntryInMap() {
MapFieldValueFilter<String, WebPage> filter = new MapFieldValueFilter<>();
//set filter field name as outlinks
filter.setFieldName(WebPage.Field.OUTLINKS.toString());
filter.setMapKey(new Utf8("foobar.whatever"));
filter.setFilterOp(FilterOp.EQUALS);
filter.setFilterIfMissing(true);
filter.getOperands().add(new Utf8("Click here for foobar!"));
WebPage page = WebPage.newBuilder().build();
assertTrue(filter.filter("irrelevant", page));
page.getOutlinks().put(new Utf8("foobar.whatever"), new Utf8("Mismatch!"));
assertTrue(filter.filter("irrelevant", page));
page.getOutlinks().put(new Utf8("foobar.whatever"), new Utf8("Click here for foobar!"));
assertFalse(filter.filter("irrelevant", page));
}
Aggregations