use of org.apache.gora.examples.generated.WebPage in project gora by apache.
the class DataStoreTestUtil method testPutMap.
public static void testPutMap(DataStore<String, WebPage> store) throws Exception {
store.createSchema();
WebPage page = WebPage.newBuilder().build();
page.setUrl(new Utf8("http://example.com"));
page.getOutlinks().put(new Utf8("http://example2.com"), new Utf8("anchor2"));
page.getOutlinks().put(new Utf8("http://example3.com"), new Utf8("anchor3"));
page.getOutlinks().put(new Utf8("http://example3.com"), new Utf8("anchor4"));
store.put("com.example/http", page);
store.close();
}
use of org.apache.gora.examples.generated.WebPage in project gora by apache.
the class DataStoreTestUtil method testUpdateWebPagePutToNullableMap.
public static void testUpdateWebPagePutToNullableMap(DataStore<String, WebPage> dataStore) throws Exception {
dataStore.createSchema();
String[] urls = { "http://a.com/a", "http://b.com/b", "http://c.com/c", "http://d.com/d", "http://e.com/e", "http://f.com/f", "http://g.com/g" };
String header = "header";
String[] headers = { "firstHeader", "secondHeader", "thirdHeader", "fourthHeader", "fifthHeader", "sixthHeader" };
for (String url : urls) {
WebPage webPage = WebPage.newBuilder().build();
webPage.setUrl(new Utf8(url));
//test put for nullable map field
// we put data to the 'headers' field which is a Map with default value of 'null'
webPage.setHeaders(new HashMap<CharSequence, CharSequence>());
for (int j = 0; j < headers.length; j += 2) {
webPage.getHeaders().put(new Utf8(header + j), new Utf8(headers[j]));
}
dataStore.put(webPage.getUrl().toString(), webPage);
}
dataStore.flush();
for (String url : urls) {
WebPage webPage = dataStore.get(url);
//webPage.getHeaders().clear(); //TODO clear method does not work
webPage.setHeaders(new HashMap<CharSequence, CharSequence>());
for (int j = 1; j < headers.length; j += 2) {
webPage.getHeaders().put(new Utf8(header + j), new Utf8(headers[j]));
}
dataStore.put(webPage.getUrl().toString(), webPage);
}
dataStore.flush();
for (String url : urls) {
WebPage webPage = dataStore.get(url);
int count = 0;
for (int j = 1; j < headers.length; j += 2) {
CharSequence headerSample = webPage.getHeaders().get(new Utf8(header + j));
assertNotNull(headerSample);
assertEquals(headers[j], headerSample.toString());
count++;
}
assertEquals(count, webPage.getHeaders().size());
}
}
Aggregations