Search in sources :

Example 41 with WebPage

use of org.apache.gora.examples.generated.WebPage in project gora by apache.

the class DataStoreTestUtil method testPutMixedMapTypes.

public static void testPutMixedMapTypes(DataStore<String, WebPage> store) {
    WebPage webpage = createWebPage();
    webpage.getByteData().put(new Utf8("byteData"), ByteBuffer.wrap(ByteUtils.toBytes("hello map")));
    webpage.getStringData().put(new Utf8("stringData"), "hello map");
    store.createSchema();
    store.put(webpage.getUrl().toString(), webpage);
    store.flush();
    assertNotNull(store.get(webpage.getUrl().toString()));
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) Utf8(org.apache.avro.util.Utf8)

Example 42 with WebPage

use of org.apache.gora.examples.generated.WebPage in project gora by apache.

the class MemStoreTest method testGetMissingValue.

@Test
public void testGetMissingValue() {
    DataStore<String, WebPage> store = new MemStore<>();
    WebPage nullWebPage = store.get("missing", new String[0]);
    assertNull(nullWebPage);
    store.close();
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) Test(org.junit.Test)

Example 43 with WebPage

use of org.apache.gora.examples.generated.WebPage in project gora by apache.

the class MemStoreTest method testGetWithFields.

@Test
public void testGetWithFields() throws Exception {
    DataStore<String, WebPage> store = new MemStore<>();
    BeanFactory<String, WebPage> beanFactory = new BeanFactoryImpl<>(String.class, WebPage.class);
    store.setBeanFactory(beanFactory);
    WebPageDataCreator.createWebPageData(store);
    String[] interestFields = new String[2];
    interestFields[0] = "url";
    interestFields[1] = "content";
    WebPage page = store.get(URLS[1], interestFields);
    assertNotNull(page);
    assertNotNull(page.getUrl());
    assertEquals(page.getUrl().toString(), URLS[1]);
    assertNotNull(page.getContent());
    assertEquals("Map of Outlinks should have a size of '0' as it is omitted at retrieval", 0, page.getOutlinks().size());
    assertEquals("Map of Parsed Content should have a size of '0' as it is omitted at retrieval", 0, page.getParsedContent().size());
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) BeanFactoryImpl(org.apache.gora.persistency.impl.BeanFactoryImpl) Test(org.junit.Test)

Example 44 with WebPage

use of org.apache.gora.examples.generated.WebPage in project gora by apache.

the class TestPersistentBase method testGetFieldIndex.

/**
   * Assert that field positions as found within the SCHEMA array
   * are as we would expect by accessing them directly. 
   */
@Test
public void testGetFieldIndex() {
    WebPage page = WebPage.newBuilder().build();
    for (int i = 0; i < WebPage.SCHEMA$.getFields().toArray().length; i++) {
        int index = page.getSchema().getFields().get(i).pos();
        assertEquals(i, index);
    }
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) Test(org.junit.Test)

Example 45 with WebPage

use of org.apache.gora.examples.generated.WebPage in project gora by apache.

the class TestAvroUtils method testDeepClonePersistent.

@Test
public void testDeepClonePersistent() throws Exception {
    CharSequence url = new Utf8("http://gora.apache.org/");
    WebPage.Builder builder = WebPage.newBuilder().setUrl(url).setContent(ByteBuffer.wrap("Gora".getBytes("UTF-8")));
    WebPage webPage = builder.build();
    WebPage clonedWebPage = AvroUtils.deepClonePersistent(webPage);
    assertThat(clonedWebPage, is(notNullValue()));
    assertThat(clonedWebPage.getUrl(), is(equalTo(url)));
    assertThat(clonedWebPage.getContent(), is(notNullValue()));
    String clonedWebPageContent = new String(clonedWebPage.getContent().array(), "UTF-8");
    assertThat(clonedWebPageContent, is(equalTo("Gora")));
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) Utf8(org.apache.avro.util.Utf8) Test(org.junit.Test)

Aggregations

WebPage (org.apache.gora.examples.generated.WebPage)67 Test (org.junit.Test)33 Utf8 (org.apache.avro.util.Utf8)32 DBObject (com.mongodb.DBObject)7 Configuration (org.apache.hadoop.conf.Configuration)6 Employee (org.apache.gora.examples.generated.Employee)5 Metadata (org.apache.gora.examples.generated.Metadata)4 BeanFactoryImpl (org.apache.gora.persistency.impl.BeanFactoryImpl)4 ByteBuffer (java.nio.ByteBuffer)3 org.apache.hadoop.hbase.client (org.apache.hadoop.hbase.client)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Field (org.apache.avro.Schema.Field)2 TokenDatum (org.apache.gora.examples.generated.TokenDatum)2 FilterList (org.apache.gora.filter.FilterList)2 TableName (org.apache.hadoop.hbase.TableName)2 Job (org.apache.hadoop.mapreduce.Job)2 Properties (java.util.Properties)1