Search in sources :

Example 81 with SortedSet

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();
}
Also used : TreeSet(java.util.TreeSet) List(java.util.List) ArrayList(java.util.ArrayList) Criteria(org.hibernate.Criteria) SortedSet(java.util.SortedSet) Session(org.hibernate.Session) Test(org.junit.Test)

Example 82 with SortedSet

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);
}
Also used : SortedSet(java.util.SortedSet)

Example 83 with SortedSet

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
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) WAL(org.apache.hadoop.hbase.wal.WAL) MultiVersionConcurrencyControl(org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) ArrayList(java.util.ArrayList) WALActionsListener(org.apache.hadoop.hbase.regionserver.wal.WALActionsListener) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) ReplicationEndpoint(org.apache.hadoop.hbase.replication.ReplicationEndpoint) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) WALKey(org.apache.hadoop.hbase.wal.WALKey) WALEdit(org.apache.hadoop.hbase.regionserver.wal.WALEdit) WALFactory(org.apache.hadoop.hbase.wal.WALFactory) Map(java.util.Map) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 84 with SortedSet

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;
}
Also used : Path(org.apache.hadoop.fs.Path) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) ReplicationPeer(org.apache.hadoop.hbase.replication.ReplicationPeer) SortedSet(java.util.SortedSet)

Example 85 with SortedSet

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());
}
Also used : NavigableSet(java.util.NavigableSet) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Aggregations

SortedSet (java.util.SortedSet)127 TreeSet (java.util.TreeSet)49 Iterator (java.util.Iterator)43 HashMap (java.util.HashMap)24 NavigableSet (java.util.NavigableSet)22 ArrayList (java.util.ArrayList)20 Map (java.util.Map)20 List (java.util.List)19 Set (java.util.Set)19 TreeMap (java.util.TreeMap)18 HashSet (java.util.HashSet)15 Test (org.junit.Test)13 IOException (java.io.IOException)12 Collection (java.util.Collection)10 Comparator (java.util.Comparator)7 LinkedHashMap (java.util.LinkedHashMap)7 LinkedList (java.util.LinkedList)5 SolverException (cbit.vcell.solver.SolverException)3 TestStringSortedSetGenerator (com.google.common.collect.testing.TestStringSortedSetGenerator)3 File (java.io.File)3