use of java.util.SortedSet in project hibernate-orm by hibernate.
the class FooBarTest method testSortables.
@Test
public void testSortables() throws Exception {
Session s = openSession();
s.beginTransaction();
Baz b = new Baz();
b.setName("name");
SortedSet ss = new TreeSet();
ss.add(new Sortable("foo"));
ss.add(new Sortable("bar"));
ss.add(new Sortable("baz"));
b.setSortablez(ss);
s.save(b);
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
Criteria cr = s.createCriteria(Baz.class);
cr.setFetchMode("topGlarchez", FetchMode.SELECT);
List result = cr.addOrder(Order.asc("name")).list();
assertTrue(result.size() == 1);
b = (Baz) result.get(0);
assertTrue(b.getSortablez().size() == 3);
assertEquals(((Sortable) b.getSortablez().iterator().next()).getName(), "bar");
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
result = s.createQuery("from Baz baz left join fetch baz.sortablez order by baz.name asc").list();
b = (Baz) result.get(0);
assertTrue(b.getSortablez().size() == 3);
assertEquals(((Sortable) b.getSortablez().iterator().next()).getName(), "bar");
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
result = s.createQuery("from Baz baz order by baz.name asc").list();
b = (Baz) result.get(0);
assertTrue(b.getSortablez().size() == 3);
assertEquals(((Sortable) b.getSortablez().iterator().next()).getName(), "bar");
s.delete(b);
s.getTransaction().commit();
s.close();
}
use of java.util.SortedSet in project hibernate-orm by hibernate.
the class PersistentSortedSet method tailSet.
@Override
@SuppressWarnings("unchecked")
public SortedSet tailSet(Object fromElement) {
read();
final SortedSet tailSet = ((SortedSet) set).tailSet(fromElement);
return new SubSetProxy(tailSet);
}
use of java.util.SortedSet in project hbase by apache.
the class TestReplicationSourceManager method testLogRoll.
@Test
public void testLogRoll() throws Exception {
long baseline = 1000;
long time = baseline;
MultiVersionConcurrencyControl mvcc = new MultiVersionConcurrencyControl();
KeyValue kv = new KeyValue(r1, f1, r1);
WALEdit edit = new WALEdit();
edit.add(kv);
List<WALActionsListener> listeners = new ArrayList<>(1);
listeners.add(replication);
final WALFactory wals = new WALFactory(utility.getConfiguration(), listeners, URLEncoder.encode("regionserver:60020", "UTF8"));
final WAL wal = wals.getWAL(hri.getEncodedNameAsBytes(), hri.getTable().getNamespace());
manager.init();
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("tableame"));
htd.addFamily(new HColumnDescriptor(f1));
NavigableMap<byte[], Integer> scopes = new TreeMap<>(Bytes.BYTES_COMPARATOR);
for (byte[] fam : htd.getFamiliesKeys()) {
scopes.put(fam, 0);
}
// Testing normal log rolling every 20
for (long i = 1; i < 101; i++) {
if (i > 1 && i % 20 == 0) {
wal.rollWriter();
}
LOG.info(i);
final long txid = wal.append(hri, new WALKey(hri.getEncodedNameAsBytes(), test, System.currentTimeMillis(), mvcc, scopes), edit, true);
wal.sync(txid);
}
// Simulate a rapid insert that's followed
// by a report that's still not totally complete (missing last one)
LOG.info(baseline + " and " + time);
baseline += 101;
time = baseline;
LOG.info(baseline + " and " + time);
for (int i = 0; i < 3; i++) {
wal.append(hri, new WALKey(hri.getEncodedNameAsBytes(), test, System.currentTimeMillis(), mvcc, scopes), edit, true);
}
wal.sync();
int logNumber = 0;
for (Map.Entry<String, SortedSet<String>> entry : manager.getWALs().get(slaveId).entrySet()) {
logNumber += entry.getValue().size();
}
assertEquals(6, logNumber);
wal.rollWriter();
manager.logPositionAndCleanOldLogs(manager.getSources().get(0).getCurrentPath(), "1", 0, false, false);
wal.append(hri, new WALKey(hri.getEncodedNameAsBytes(), test, System.currentTimeMillis(), mvcc, scopes), edit, true);
wal.sync();
assertEquals(1, manager.getWALs().size());
// TODO Need a case with only 2 WALs and we only want to delete the first one
}
use of java.util.SortedSet in project hbase by apache.
the class ReplicationSourceManager method addSource.
/**
* Add sources for the given peer cluster on this region server. For the newly added peer, we only
* need to enqueue the latest log of each wal group and do replication
* @param id the id of the peer cluster
* @return the source that was created
* @throws IOException
*/
protected ReplicationSourceInterface addSource(String id) throws IOException, ReplicationException {
ReplicationPeerConfig peerConfig = replicationPeers.getReplicationPeerConfig(id);
ReplicationPeer peer = replicationPeers.getConnectedPeer(id);
ReplicationSourceInterface src = getReplicationSource(this.conf, this.fs, this, this.replicationQueues, this.replicationPeers, server, id, this.clusterId, peerConfig, peer);
synchronized (this.walsById) {
this.sources.add(src);
Map<String, SortedSet<String>> walsByGroup = new HashMap<>();
this.walsById.put(id, walsByGroup);
// Add the latest wal to that source's queue
synchronized (latestPaths) {
if (this.latestPaths.size() > 0) {
for (Path logPath : latestPaths) {
String name = logPath.getName();
String walPrefix = AbstractFSWALProvider.getWALPrefixFromWALName(name);
SortedSet<String> logs = new TreeSet<>();
logs.add(name);
walsByGroup.put(walPrefix, logs);
try {
this.replicationQueues.addLog(id, name);
} catch (ReplicationException e) {
String message = "Cannot add log to queue when creating a new source, queueId=" + id + ", filename=" + name;
server.stop(message);
throw e;
}
src.enqueueLog(logPath);
}
}
}
}
src.startup();
return src;
}
use of java.util.SortedSet in project mapdb by jankotek.
the class ConcurrentSkipListSetTest method testHeadSetContents.
/**
* headSet returns set with keys in requested range
*/
public void testHeadSetContents() {
NavigableSet set = set5();
SortedSet sm = set.headSet(four);
assertTrue(sm.contains(one));
assertTrue(sm.contains(two));
assertTrue(sm.contains(three));
assertFalse(sm.contains(four));
assertFalse(sm.contains(five));
Iterator i = sm.iterator();
Object k;
k = (Integer) (i.next());
assertEquals(one, k);
k = (Integer) (i.next());
assertEquals(two, k);
k = (Integer) (i.next());
assertEquals(three, k);
assertFalse(i.hasNext());
sm.clear();
assertTrue(sm.isEmpty());
assertEquals(2, set.size());
assertEquals(four, set.first());
}
Aggregations