@Test public void testChronologize() { Map<Long, Set<Value>> map = Maps.newLinkedHashMap(); Set<Value> set = Sets.newLinkedHashSet(); Set<Value> allValues = Sets.newLinkedHashSet(); long recordId = TestData.getLong(); PrimaryKey primaryKey = PrimaryKey.wrap(recordId); TableRecord record = TableRecord.create(primaryKey); for (long i = 30; i <= 35; i++) { Value value = null; while (value == null || !allValues.add(value)) { value = TestData.getValue(); } record.append( getRevision(primaryKey, Text.wrapCached("name"), value)); set.add(value); } long start = Time.now(); for (long i = 36; i <= 45; i++) { set = Sets.newLinkedHashSet(set); Value value = null; while (value == null || !allValues.add(value)) { value = TestData.getValue(); } record.append( getRevision(primaryKey, Text.wrapCached("name"), value)); set.add(value); map.put(i, set); } long end = Time.now(); for (long i = 51; i <= 60; i++) { Value value = null; while (value == null || !allValues.add(value)) { value = TestData.getValue(); } record.append( getRevision(primaryKey, Text.wrapCached("name"), value)); } Map<Long, Set<Value>> newMap = record .chronologize(Text.wrapCached("name"), start, end); long key = 36; for (Entry<Long, Set<Value>> e : newMap.entrySet()) { Set<Value> result = e.getValue(); Assert.assertEquals(map.get(key), result); key++; } }
public Map<Long, Set<Value>> chronologize(Text key, long start, long end) { read.lock(); try { Map<Long, Set<Value>> context = Maps.newLinkedHashMap(); List<CompactRevision<Value>> revisions = history.get(key); Set<Value> snapshot = Sets.newLinkedHashSet(); if(revisions != null) { Iterator<CompactRevision<Value>> it = revisions.iterator(); while (it.hasNext()) { CompactRevision<Value> revision = it.next(); long timestamp = revision.getVersion(); if(timestamp >= end) { break; } else { Action action = revision.getType(); snapshot = Sets.newLinkedHashSet(snapshot); Value value = revision.getValue(); if(action == Action.ADD) { snapshot.add(value); } else if(action == Action.REMOVE) { snapshot.remove(value); } if(timestamp >= start && !snapshot.isEmpty()) { context.put(timestamp, snapshot); } } } } if(snapshot.isEmpty()) { context.put(Time.NONE, snapshot); } return context; } finally { read.unlock(); } }
TableRecord extends BrowsableRecord<PrimaryKey, Text, Value> { public Map<Long, Set<Value>> chronologize(Text key, long start, long end) { read.lock(); try { Map<Long, Set<Value>> context = Maps.newLinkedHashMap(); List<CompactRevision<Value>> revisions = history.get(key); Set<Value> snapshot = Sets.newLinkedHashSet(); if(revisions != null) { Iterator<CompactRevision<Value>> it = revisions.iterator(); while (it.hasNext()) { CompactRevision<Value> revision = it.next(); long timestamp = revision.getVersion(); if(timestamp >= end) { break; } else { Action action = revision.getType(); snapshot = Sets.newLinkedHashSet(snapshot); Value value = revision.getValue(); if(action == Action.ADD) { snapshot.add(value); } else if(action == Action.REMOVE) { snapshot.remove(value); } if(timestamp >= start && !snapshot.isEmpty()) { context.put(timestamp, snapshot); } } } } if(snapshot.isEmpty()) { context.put(Time.NONE, snapshot); } return context; } finally { read.unlock(); } } }
TableRecord extends BrowsableRecord<PrimaryKey, Text, Value> { public Map<Long, Set<Value>> chronologize(Text key, long start, long end) { read.lock(); try { Map<Long, Set<Value>> context = Maps.newLinkedHashMap(); List<CompactRevision<Value>> revisions = history.get(key); Set<Value> snapshot = Sets.newLinkedHashSet(); if(revisions != null) { Iterator<CompactRevision<Value>> it = revisions.iterator(); while (it.hasNext()) { CompactRevision<Value> revision = it.next(); long timestamp = revision.getVersion(); if(timestamp >= end) { break; } else { Action action = revision.getType(); snapshot = Sets.newLinkedHashSet(snapshot); Value value = revision.getValue(); if(action == Action.ADD) { snapshot.add(value); } else if(action == Action.REMOVE) { snapshot.remove(value); } if(timestamp >= start && !snapshot.isEmpty()) { context.put(timestamp, snapshot); } } } } if(snapshot.isEmpty()) { context.put(Time.NONE, snapshot); } return context; } finally { read.unlock(); } } @PackagePrivate @DoNotInvoke protected  TableRecord(PrimaryKey locator, @Nullable Text key); }
TableRecord extends BrowsableRecord<PrimaryKey, Text, Value> { public Map<Long, Set<Value>> chronologize(Text key, long start, long end) { read.lock(); try { Map<Long, Set<Value>> context = Maps.newLinkedHashMap(); List<CompactRevision<Value>> revisions = history.get(key); Set<Value> snapshot = Sets.newLinkedHashSet(); if(revisions != null) { Iterator<CompactRevision<Value>> it = revisions.iterator(); while (it.hasNext()) { CompactRevision<Value> revision = it.next(); long timestamp = revision.getVersion(); if(timestamp >= end) { break; } else { Action action = revision.getType(); snapshot = Sets.newLinkedHashSet(snapshot); Value value = revision.getValue(); if(action == Action.ADD) { snapshot.add(value); } else if(action == Action.REMOVE) { snapshot.remove(value); } if(timestamp >= start && !snapshot.isEmpty()) { context.put(timestamp, snapshot); } } } } if(snapshot.isEmpty()) { context.put(Time.NONE, snapshot); } return context; } finally { read.unlock(); } } @PackagePrivate @DoNotInvoke protected  TableRecord(PrimaryKey locator, @Nullable Text key); static TableRecord create(PrimaryKey locator); static TableRecord createPartial(PrimaryKey locator, Text key); Map<Long, String> audit(); Map<Long, String> audit(Text key); Map<Long, Set<Value>> chronologize(Text key, long start, long end); Set<Value> fetch(Text key); Set<Value> fetch(Text key, long timestamp); boolean ping(); boolean verify(Text key, Value value); boolean verify(Text key, Value value, long timestamp); }
TableRecord extends BrowsableRecord<PrimaryKey, Text, Value> { public Map<Long, Set<Value>> chronologize(Text key, long start, long end) { read.lock(); try { Map<Long, Set<Value>> context = Maps.newLinkedHashMap(); List<CompactRevision<Value>> revisions = history.get(key); Set<Value> snapshot = Sets.newLinkedHashSet(); if(revisions != null) { Iterator<CompactRevision<Value>> it = revisions.iterator(); while (it.hasNext()) { CompactRevision<Value> revision = it.next(); long timestamp = revision.getVersion(); if(timestamp >= end) { break; } else { Action action = revision.getType(); snapshot = Sets.newLinkedHashSet(snapshot); Value value = revision.getValue(); if(action == Action.ADD) { snapshot.add(value); } else if(action == Action.REMOVE) { snapshot.remove(value); } if(timestamp >= start && !snapshot.isEmpty()) { context.put(timestamp, snapshot); } } } } if(snapshot.isEmpty()) { context.put(Time.NONE, snapshot); } return context; } finally { read.unlock(); } } @PackagePrivate @DoNotInvoke protected  TableRecord(PrimaryKey locator, @Nullable Text key); static TableRecord create(PrimaryKey locator); static TableRecord createPartial(PrimaryKey locator, Text key); Map<Long, String> audit(); Map<Long, String> audit(Text key); Map<Long, Set<Value>> chronologize(Text key, long start, long end); Set<Value> fetch(Text key); Set<Value> fetch(Text key, long timestamp); boolean ping(); boolean verify(Text key, Value value); boolean verify(Text key, Value value, long timestamp);  }