Package org.apache.ace.range

Examples of org.apache.ace.range.SortedRangeSet


     * Tests that if we do not change anything in an {@link InputStream} while committing data, that the version is not
     * bumped for a repository.
     */
    @Test(groups = { UNIT })
    public void testCheckoutAndCommitWithoutChangeDoesNotChangeVersion() 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);
        assertFalse(repo.commit(is, 1), "Commit should be ignored");

        range = repo.getRange();
        assertEquals(1, range.getHigh(), "Version 1 should still be the most recent one");
    }
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 testCommitInitialVersionDoesChangeVersion() 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());

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

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

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

        assertTrue(repo.commit(new ByteArrayInputStream("abc-1".getBytes()), 0), "Commit should have worked.");
        assertTrue(repo.commit(new ByteArrayInputStream("abc-2".getBytes()), 1), "Commit should have worked.");
        assertTrue(repo.commit(new ByteArrayInputStream("abc-3".getBytes()), 2), "Commit should have worked.");

        SortedRangeSet range = repo.getRange();
        assertTrue(range.getHigh() == 3, "We should have 3 versions in the repository.");
    }
View Full Code Here

     * @throws IOException
     *             if anything goes wrong
     */
    private List<Event> getInternal(Descriptor descriptor) throws IOException {
        final List<Event> result = new ArrayList<Event>();
        final SortedRangeSet set = descriptor.getRangeSet();
        BufferedReader in = null;
        try {
            File log = new File(new File(m_dir, targetIDToFilename(descriptor.getTargetID())), String.valueOf(descriptor.getStoreID()));
            if (!log.isFile()) {
                return result;
            }
            in = new BufferedReader(new FileReader(log));
            String file = log.getAbsolutePath();
            long counter = 0;
            for (String line = in.readLine(); line != null; line = in.readLine()) {
                Event event = new Event(line);
                long id = event.getID();
                if ((counter != -1) && ++counter == id) {

                }
                else {
                    counter = -1;
                }
                if (set.contains(id)) {
                    result.add(event);
                }
            }
            if (counter < 1) {
                m_fileToID.remove(file);
View Full Code Here

    public Descriptor getDescriptor(String targetID, long logID) throws IOException {
        Long high = m_fileToID.get(new File(new File(m_dir, targetIDToFilename(targetID)), String.valueOf(logID)).getAbsolutePath());
        if (high != null) {
            Range r = new Range(1, high);
            return new Descriptor(targetID, logID, new SortedRangeSet(r.toRepresentation()));
        }
        List<Event> events = get(new Descriptor(targetID, logID, SortedRangeSet.FULL_SET));

        long[] idsArray = new long[events.size()];
        int i = 0;
        for (Event e : events) {
            idsArray[i++] = e.getID();
        }
        return new Descriptor(targetID, logID, new SortedRangeSet(idsArray));
    }
View Full Code Here

        // Verify the written file...
        List<Descriptor> descriptors = store.getDescriptors();

        long expectedID = 0;
        for (Descriptor desc : descriptors) {
            SortedRangeSet rangeSet = desc.getRangeSet();
            RangeIterator rangeIter = rangeSet.iterator();

            while (rangeIter.hasNext()) {
                long id = rangeIter.next();

                Event expectedEntry = null;
View Full Code Here

                            // perform a random cleanup...
                            m_store.clean();
                        }
                        List<Descriptor> descriptors = m_store.getDescriptors(TARGET_ID);
                        for (Descriptor desc : descriptors) {
                            SortedRangeSet rangeSet = desc.getRangeSet();
                            RangeIterator rangeIter = rangeSet.iterator();
                            while (rangeIter.hasNext()) {
                                m_seen.putIfAbsent(Long.valueOf(rangeIter.next()), Boolean.TRUE);
                            }
                        }
                    }
View Full Code Here

     * @see org.apache.ace.server.log.store.LogStore#get(org.apache.ace.log.LogDescriptor)
     */
    public synchronized List<LogEvent> get(LogDescriptor descriptor)
            throws IOException {
        final List<LogEvent> result = new ArrayList<LogEvent>();
        final SortedRangeSet set = descriptor.getRangeSet();
        BufferedReader in = null;
        try {
            File log = new File(new File(m_dir,
                    gatewayIDToFilename(descriptor.getGatewayID())),
                    String.valueOf(descriptor.getLogID()));
            if (!log.isFile()) {
                return result;
            }
            in = new BufferedReader(new FileReader(log));
            String file = log.getAbsolutePath();
            long counter = 0;
            for (String line = in.readLine(); line != null; line = in
                    .readLine()) {
                LogEvent event = new LogEvent(line);
                long id = event.getID();
                if ((counter != -1) && ++counter == id) {

                } else {
                    counter = -1;
                }
                if (set.contains(id)) {
                    result.add(event);
                }
            }
            if (counter < 1) {
                m_fileToID.remove(file);
View Full Code Here

        Long high = m_fileToID.get(new File(new File(m_dir,
                gatewayIDToFilename(gatewayID)), String.valueOf(logID))
                .getAbsolutePath());
        if (high != null) {
            Range r = new Range(1, high);
            return new LogDescriptor(gatewayID, logID, new SortedRangeSet(
                    r.toRepresentation()));
        }
        List<LogEvent> events = get(new LogDescriptor(gatewayID, logID,
                SortedRangeSet.FULL_SET));

        long[] idsArray = new long[events.size()];
        int i = 0;
        for (LogEvent e : events) {
            idsArray[i++] = e.getID();
        }
        return new LogDescriptor(gatewayID, logID, new SortedRangeSet(idsArray));
    }
View Full Code Here

    }

    @Override
    protected SortedRangeSet getRange(ServiceReference ref) throws IOException {
        RepositoryReplication repository = (RepositoryReplication) m_context.getService(ref);
        SortedRangeSet range = repository.getRange();
        m_context.ungetService(ref);
        return range;
    }
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.