int parsedContentCount = 0;
for (int i = 0; i < urls.length; i++) {
WebPage webPage = dataStore.newPersistent();
webPage.setUrl(new Utf8(urls[i]));
for (parsedContentCount = 0; parsedContentCount < 5; parsedContentCount++) {
webPage.addToParsedContent(new Utf8(parsedContent + i + "," + parsedContentCount));
}
for (int j = 0; j < urls.length; j += 2) {
webPage.putToOutlinks(new Utf8(anchor + j), new Utf8(urls[j]));
}
dataStore.put(webPage.getUrl().toString(), webPage);
}
dataStore.flush();
for (int i = 0; i < urls.length; i++) {
WebPage webPage = dataStore.get(urls[i]);
webPage.setContent(ByteBuffer.wrap(ByteUtils.toBytes(content + i)));
for (parsedContentCount = 5; parsedContentCount < 10; parsedContentCount++) {
webPage.addToParsedContent(new Utf8(parsedContent + i + "," + parsedContentCount));
}
webPage.getOutlinks().clear();
for (int j = 1; j < urls.length; j += 2) {
webPage.putToOutlinks(new Utf8(anchor + j), new Utf8(urls[j]));
}
dataStore.put(webPage.getUrl().toString(), webPage);
}
dataStore.flush();
for (int i = 0; i < urls.length; i++) {
WebPage webPage = dataStore.get(urls[i]);
Assert.assertEquals(content + i, ByteUtils.toString( toByteArray(webPage.getContent()) ));
Assert.assertEquals(10, webPage.getParsedContent().size());
int j = 0;
for (Utf8 pc : webPage.getParsedContent()) {
Assert.assertEquals(parsedContent + i + "," + j, pc.toString());
j++;
}
int count = 0;
for (j = 1; j < urls.length; j += 2) {
Utf8 link = webPage.getOutlinks().get(new Utf8(anchor + j));
Assert.assertNotNull(link);
Assert.assertEquals(urls[j], link.toString());
count++;
}
Assert.assertEquals(count, webPage.getOutlinks().size());
}
for (int i = 0; i < urls.length; i++) {
WebPage webPage = dataStore.get(urls[i]);
for (int j = 0; j < urls.length; j += 2) {
webPage.putToOutlinks(new Utf8(anchor + j), new Utf8(urls[j]));
}
dataStore.put(webPage.getUrl().toString(), webPage);
}
dataStore.flush();
for (int i = 0; i < urls.length; i++) {
WebPage webPage = dataStore.get(urls[i]);
int count = 0;
for (int j = 0; j < urls.length; j++) {
Utf8 link = webPage.getOutlinks().get(new Utf8(anchor + j));
Assert.assertNotNull(link);
Assert.assertEquals(urls[j], link.toString());
count++;
}
}