Package org.apache.ace.feedback

Examples of org.apache.ace.feedback.Descriptor


        assert descriptor.getRangeSet().toRepresentation().equals("2-3") : "There should be nothing in the diff between the set in the descriptor and the check-set.";
    }

    @Test(groups = { UNIT })
    public void deserializeMultiRangeDescriptor() {
        Descriptor descriptor = new Descriptor("gwid,1,1-4$k6$k8$k10-20");
        assert descriptor.getTargetID().equals("gwid") : "Target ID not correctly parsed.";
        assert descriptor.getStoreID() == 1 : "Log ID not correctly parsed.";
        String representation = descriptor.getRangeSet().toRepresentation();
        assert representation.equals("1-4,6,8,10-20") : "There should be nothing in the diff between the set in the descriptor and the check-set, but we parsed: " + representation;
    }
View Full Code Here


    }

    @Test(groups = { UNIT })
    public void deserializeMultiRangeDescriptorWithFunnyGWID() {
        String line = "gw$$id,1,1-4$k6$k8$k10-20";
        Descriptor descriptor = new Descriptor(line);
        assert descriptor.getTargetID().equals("gw$id") : "Target ID not correctly parsed.";
        assert descriptor.getStoreID() == 1 : "Log ID not correctly parsed.";
        assert line.equals(descriptor.toRepresentation()) : "Converting the line back to the representation failed.";
        String representation = descriptor.getRangeSet().toRepresentation();
        assert representation.equals("1-4,6,8,10-20") : "There should be nothing in the diff between the set in the descriptor and the check-set, but we parsed: " + representation;
    }
View Full Code Here

        assert representation.equals("1-4,6,8,10-20") : "There should be nothing in the diff between the set in the descriptor and the check-set, but we parsed: " + representation;
    }

    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
    public void deserializeInvalidDescriptor() throws Exception {
        new Descriptor("invalidStringRepresentation");
    }
View Full Code Here

        try {
            queryReader = new BufferedReader(new InputStreamReader(queryInput));
            String rangeString = queryReader.readLine();
            if (rangeString != null) {
                try {
                    return new Descriptor(rangeString);
                }
                catch (IllegalArgumentException iae) {
                    throw new IOException("Could not determine highest remote event id, received malformed event range (" + rangeString + ")");
                }
            }
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

        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

    // Handle a call to the query 'command'
    protected boolean handleQuery(String targetID, String logID, String filter, ServletOutputStream output) throws IOException {
        if ((targetID != null) && (logID != null)) {
            // target and log id are specified, return only the range that matches these id's
            Descriptor range = m_store.getDescriptor(targetID, Long.parseLong(logID));
            output.print(range.toRepresentation());
            return true;
        }
        else if ((targetID == null) && (logID == null)) {
            // no target or log id has been specified, return all ranges
            List<Descriptor> ranges = m_store.getDescriptors();
            for (Descriptor range : ranges) {
                output.print(range.toRepresentation() + "\n");
            }
            return true;
        }
        return false;
    }
View Full Code Here

    // Handle a call to the receive 'command'
    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

    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

                cached = true;
            }
        }
        List<Event> events = null;
        if (!cached) {
            events = getInternal(new Descriptor(targetID, logID, SortedRangeSet.FULL_SET));

            // remove duplicates first
            list.removeAll(events);
        }
View Full Code Here

TOP

Related Classes of org.apache.ace.feedback.Descriptor

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.