Package krati.retention.clock

Examples of krati.retention.clock.Clock


        }
    }
   
    public void testApi() throws Exception {
        int cnt = getEventBatchSize() + _rand.nextInt(getNumRetentionBatches() * getEventBatchSize() / 2);
        Clock clock = _clockFactory.next();
        Clock minClock = clock;
        _retention.put(nextEvent(clock));
       
        // Create an idle clock
        Clock idleClock0 = _clockFactory.next();
       
        clock = _clockFactory.next();
        _retention.put(nextEvent(clock));
       
        // Create an idle clock
        Clock idleClock1 = _clockFactory.next();
       
        for(int i = 2; i < cnt; i++) {
            clock = _clockFactory.next();
            _retention.put(nextEvent(clock));
        }
        Clock maxClock = clock;
       
        assertEquals(getId(), _retention.getId());
       
        Position pos = _retention.getPosition();
        assertEquals((long)cnt, pos.getOffset());
        assertEquals(cnt, _retention.getOffset());
       
        assertTrue(minClock.compareTo(_retention.getMinClock()) == Occurred.EQUICONCURRENTLY);
        assertTrue(maxClock.compareTo(_retention.getMaxClock()) == Occurred.EQUICONCURRENTLY);
       
        Position sincePosition = _retention.getPosition(idleClock0);
        assertEquals(getId(), sincePosition.getId());
        assertEquals(0, sincePosition.getOffset());
       
View Full Code Here


        RetentionReaderThread<T> reader = new RetentionReaderThread<T>(_retention);
        reader.start();
       
        // Add new events into the Retention
        for(int i = 0; i < cnt; i++) {
            Clock clock = _clockFactory.next();
            _retention.put(nextEvent(clock));
           
            // Random flush
            if(_rand.nextFloat() < 0.05f) {
                _retention.flush();
            }
        }
       
        // Final flush
        _retention.flush();
       
        // Stop the Retention reader thread
        reader.stop(_retention.getOffset());
        reader.join();
       
        assertEquals(_retention.getOffset(), reader.getReadCount());
       
        Clock minClock = _retention.getMinClock();
        Clock maxClock = _retention.getMaxClock();
        assertTrue(minClock.after(Clock.ZERO));
        assertTrue(minClock.compareTo(maxClock) == Occurred.BEFORE);
       
        // Close retention
        _retention.close();
View Full Code Here

        }
    }
   
    public void testApiBasics() {
        Iterator<String> iter;
        Clock clock;
       
        iter = _clock.sourceIterator();
        while(iter.hasNext()) {
            String source = iter.next();
            assertEquals(0, _clock.getLWMScn(source));
            assertEquals(0, _clock.getHWMScn(source));
        }
       
        clock = _clock.current();
       
        // Save hwmScn
        iter = _clock.sourceIterator();
        while(iter.hasNext()) {
            String source = iter.next();
            long hwm = _clock.getHWMScn(source) + _rand.nextInt(100) + 1;
            _clock.updateHWMark(source, hwm);
            assertTrue(_clock.getLWMScn(source) < _clock.getHWMScn(source));
            assertTrue(clock.before(_clock.current()));
            clock = _clock.current();
        }
       
        assertTrue(clock.compareTo(_clock.current()) == Occurred.EQUICONCURRENTLY);
       
        // Sync water marks
        _clock.syncWaterMarks();
       
        // Check lwmScn = hwmScn
View Full Code Here

            _clock.setHWMark(source, _clock.getHWMScn(source) + _rand.nextInt(1000) + 1);
            assertTrue(_clock.getLWMScn(source) < _clock.getHWMScn(source));
            assertEquals(0, _clock.getWaterMark(source, Clock.ZERO));
        }
       
        Clock current = _clock.current();
       
        iter = _clock.sourceIterator();
        while(iter.hasNext()) {
            String source = iter.next();
            assertEquals(_clock.getHWMScn(source), _clock.getWaterMark(source, current));
View Full Code Here

* 08/11, 2011 - Created
*/
public class TestClock extends TestCase {
   
    public void testEquals() {
        Clock c1 = new Clock(2, 12, 5);
        Clock c2 = new Clock(2, 12, 5);
        Clock c3 = new Clock(2, 12, 5, 0);
        assertEquals(c1, c2);
        assertFalse(c1.equals(c3));
    }
View Full Code Here

    }
   
    public void testApiBasics() {
        RandomClockFactory f = new RandomClockFactory(3);
       
        Clock c1 = f.next();
        Clock c2 = f.next();
        assertTrue(c1.before(c2));
        assertTrue(c2.after(c1));
       
        long[] scnValues = (long[])c1.values().clone();
        Clock c = new Clock(scnValues);
        assertTrue(c.compareTo(c1) == Occurred.EQUICONCURRENTLY);
        assertTrue(c1.compareTo(c) == Occurred.EQUICONCURRENTLY);
       
        scnValues[0] = scnValues[0] + 1;
        c = new Clock(scnValues);
        assertTrue(c.after(c1));
        assertTrue(c1.before(c));
       
        scnValues[1] = c.values()[1] - 1;
        c = new Clock(scnValues);
       
        assertEquals(Occurred.CONCURRENTLY, c.compareTo(c1));
       
        long[] scnValuesNew = new long[2];
        scnValuesNew[0] = scnValuesNew[0];
        scnValuesNew[1] = scnValuesNew[1];
        c = new Clock(scnValuesNew);
       
        try {
            c.compareTo(c1);
            assertTrue(false);
        } catch(IncomparableClocksException e) {
            assertTrue(true);
        }
    }
View Full Code Here

    }
   
    public void testClockSerializer() {
        ClockSerializer serializer = new ClockSerializer();
        RandomClockFactory f = new RandomClockFactory(5);
        Clock c = f.next();
       
        byte[] raw = c.toByteArray();
        Clock c2 = Clock.parseClock(raw);
        Clock c3 = serializer.deserialize(raw);
       
        assertEquals(Occurred.EQUICONCURRENTLY, c.compareTo(c2));
        assertEquals(Occurred.EQUICONCURRENTLY, c.compareTo(c3));
       
        String str = c.toString();
        Clock c4 = Clock.parseClock(str);
        assertEquals(Occurred.EQUICONCURRENTLY, c.compareTo(c4));
       
        assertTrue(c.after(Clock.ZERO));
    }
View Full Code Here

       
        assertTrue(c.after(Clock.ZERO));
    }
   
    public void testClockZero() {
        Clock c1 = Clock.parseClock(Clock.ZERO.toByteArray());
        assertEquals(Clock.ZERO, c1);
       
        Clock c2 = Clock.parseClock(Clock.ZERO.toString());
        assertEquals(Clock.ZERO, c2);
       
        SimplePosition position = new SimplePosition(1, 23467L, Clock.ZERO);
        Clock c3 = SimplePosition.parsePosition(position.toString()).getClock();
        assertEquals(Clock.ZERO, c3);
    }
View Full Code Here

                createBatchSerializer(),
                getEventBatchSize());
    }
   
    public void testRetentionPolicy() throws Exception {
        Clock clock;
        Clock startClock;
       
        clock = _clockFactory.next();
        startClock = clock;
        _retention.put(nextEvent(clock));
        assertTrue(_retention.getMinClock().compareTo(startClock) == Occurred.EQUICONCURRENTLY);
View Full Code Here

import krati.retention.Position;

public class TestSimplePosition extends TestCase {
   
    public void testStringSerialization() {
        Position p1 = new SimplePosition(10, 5, 3, new Clock(11,17,23));
        Position p2 = new SimplePosition(10, 5, 3, new Clock(11,17,23));
        Position p3 = new SimplePosition(2, 4, 6, new Clock(8,10,12));
        assertEquals(p1, p2);
        assertFalse(p1.equals(p3));
    }
View Full Code Here

TOP

Related Classes of krati.retention.clock.Clock

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.