Package org.apache.ace.range

Examples of org.apache.ace.range.SortedRangeSet


    public long getLimit() {
        return m_limit;
    }

    public SortedRangeSet getRange() throws IOException {
        return new SortedRangeSet(getVersions());
    }
View Full Code Here


                    if (line == null) {
                        throw new IOException("Repository not found: customer=" + m_customer + ", name=" + m_name + " for " + url.toExternalForm());
                    }

                    String representation = line.substring(line.lastIndexOf(','));
                    return new SortedRangeSet(representation);
                }
                finally {
                    reader.close();
                }
            }
View Full Code Here

    private URL createQueryURL(URL master, String customer, String name) throws MalformedURLException {
        return new URL(master, String.format("/replication/query?customer=%s&name=%s", customer, name));
    }

    private boolean replicateRepository(URL master, String customer, String name, RepositoryReplication repository, HttpURLConnection queryConn) throws IOException {
        SortedRangeSet localRange = repository.getRange();
        boolean result = false;

        BufferedReader reader = new BufferedReader(new InputStreamReader(queryConn.getInputStream()));
        try {
            String line = reader.readLine();
            int i = line.lastIndexOf(',');
            if (i <= 0) {
                return result;
            }

            SortedRangeSet remoteRange = new SortedRangeSet(line.substring(i + 1));

            // check the limit of the repository
            long limit = repository.getLimit();
            if (limit == Long.MAX_VALUE) {
                // no limit, sync all
                SortedRangeSet delta = localRange.diffDest(remoteRange);
                RangeIterator iterator = delta.iterator();
                while (iterator.hasNext()) {
                    long version = iterator.next();
                    replicateVersion(master, customer, name, repository, version);
                    result = true;
                }
            }
            else {
                // limit, try to get the the 'limit' newest versions
                SortedRangeSet union = localRange.union(remoteRange);
                RangeIterator iterator = union.reverseIterator();
                while (iterator.hasNext() && limit > 0) {
                    long version = iterator.next();
                    if (!localRange.contains(version)) {
                        replicateVersion(master, customer, name, repository, version);
                    }
View Full Code Here

public class LogDescriptorTest {

    @Test(groups = { UNIT })
    public void serializeDescriptor() {
        Descriptor descriptor = new Descriptor("gwid", 1, new SortedRangeSet("2-3"));
        assert descriptor.toRepresentation().equals("gwid,1,2-3") : "The representation of our descriptor is incorrect:" + descriptor.toRepresentation();
    }
View Full Code Here

        if (highestLocal == 0) {
            // No events, no need to synchronize
            return;
        }

        SortedRangeSet localRange = new SortedRangeSet("1-" + highestLocal);
        SortedRangeSet remoteRange = getDescriptor(queryInput).getRangeSet();
        SortedRangeSet delta = remoteRange.diffDest(localRange);
        RangeIterator rangeIterator = delta.iterator();

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(sendConnection.getOutputStream()));

        if (rangeIterator.hasNext()) {
            long lowest = rangeIterator.next();
            long highest = delta.getHigh();
            if (lowest <= highest) {
                List events = m_LogStore.get(logID, lowest, highestLocal > highest ? highest : highestLocal);
                Iterator iter = events.iterator();
                while (iter.hasNext()) {
                    Event current = (Event) iter.next();
View Full Code Here

        long high = 1;
        if (cursor.hasNext()) {
            DBObject row = cursor.next();
            high = (Long) row.get("id");
            return new Descriptor(targetID, logID, new SortedRangeSet(
                new Range(1, high).toRepresentation()));
        }
        else {
            return new Descriptor(targetID, logID, SortedRangeSet.FULL_SET);
        }
View Full Code Here

        task.writeDelta(task.calculateDelta(src, dest), mockWriter);

        assertTrue(task.m_calledWith.isEmpty(), "Delta of two empty lists should be empty");

        // add something to the source
        src.add(new Descriptor(targetID, 1, new SortedRangeSet("1-5")));
        task.writeDelta(task.calculateDelta(src, dest), mockWriter);

        assertEquals(task.size(), 1, "Incorrect delta");

        task.clear();

        // add an overlapping destination
        dest.add(new Descriptor(targetID, 1, new SortedRangeSet("1-3")));
        task.writeDelta(task.calculateDelta(src, dest), mockWriter);

        assertEquals(task.size(), 1, "Incorrect delta");

        RangeIterator i = task.m_calledWith.get(0).getRangeSet().iterator();
        assertEquals(i.next(), 4, "Illegal value in SortedRangeSet");
        assertEquals(i.next(), 5, "Illegal value in SortedRangeSet");
        assertFalse(i.hasNext(), "Illegal value in SortedRangeSet");

        task.clear();

        // add a non-overlapping destination
        dest.add(new Descriptor(targetID, 2, new SortedRangeSet("50-100")));
        task.writeDelta(task.calculateDelta(src, dest), mockWriter);

        assertEquals(task.size(), 1, "Incorrect delta");

        i = task.m_calledWith.get(0).getRangeSet().iterator();
        assertEquals(i.next(), 4, "Illegal value in SortedRangeSet");
        assertEquals(i.next(), 5, "Illegal value in SortedRangeSet");
        assertFalse(i.hasNext(), "Illegal value in SortedRangeSet");

        task.clear();

        // add non-overlapping source
        src.add(new Descriptor(targetID, 2, new SortedRangeSet("1-49")));
        task.writeDelta(task.calculateDelta(src, dest), mockWriter);

        assertEquals(task.size(), 2, "Incorrect delta");

        task.clear();

        // add a source with gaps
        src.add(new Descriptor(targetID, 3, new SortedRangeSet("1-10")));
        dest.add(new Descriptor(targetID, 3, new SortedRangeSet("3,5-8")));
        task.writeDelta(task.calculateDelta(src, dest), mockWriter);

        assertEquals(task.size(), 3, "Incorrect delta");
        for (Descriptor l : task.m_calledWith) {
            if (l.getStoreID() == 3) {
View Full Code Here

    protected boolean handleReceive(String targetID, String logID, String range, String filter, ServletOutputStream output) throws IOException {
        if ((targetID != null) && (logID != null)) {
            // target and log id are specified, return only the events that are in the range that matches these id's
            if (range != null) {
                Descriptor storeDescriptor = m_store.getDescriptor(targetID, Long.parseLong(logID));
                outputRange(output, new Descriptor(storeDescriptor.getTargetID(), storeDescriptor.getStoreID(), new SortedRangeSet(range)));
            }
            else {
                outputRange(output, m_store.getDescriptor(targetID, Long.parseLong(logID)));
            }
            return true;
View Full Code Here

        List<Descriptor> result = new ArrayList<Descriptor>();
        for (Descriptor s : source) {
            Descriptor diffs = s;
            for (Descriptor d : destination) {
                if ((s.getStoreID() == d.getStoreID()) && (s.getTargetID().equals(d.getTargetID()))) {
                    SortedRangeSet rangeDiff = d.getRangeSet().diffDest(s.getRangeSet());
                    if (!isEmptyRangeSet(rangeDiff)) {
                        diffs = new Descriptor(s.getTargetID(), s.getStoreID(), rangeDiff);
                    }
                    else {
                        diffs = null;
View Full Code Here

     * Tests that if we do change something in an {@link InputStream} while committing data, that the version is bumped
     * for a repository.
     */
    @Test(groups = { UNIT })
    public void testCheckoutAndCommitWithChangeDoesChangeVersion() throws Exception {
        SortedRangeSet range;
        RepositoryImpl repo = new RepositoryImpl(new File(m_baseDir, "data"), new File(m_baseDir, "tmp"), true);
        InputStream data = new ByteArrayInputStream("abc".getBytes());

        assertTrue(repo.put(data, 1), "Put should have succeeded");

        range = repo.getRange();
        assertEquals(1, range.getHigh(), "Version 1 should be the most recent one");

        InputStream is = repo.checkout(1);
        assertNotNull(is, "Nothing checked out?!");

        data = new ByteArrayInputStream("def".getBytes());

        assertTrue(repo.commit(data, 1), "Commit should NOT be ignored");

        range = repo.getRange();
        assertEquals(2, range.getHigh());
    }
View Full Code Here

TOP

Related Classes of org.apache.ace.range.SortedRangeSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.