Package com.linkedin.databus.core.util

Examples of com.linkedin.databus.core.util.BufferPositionParser


    {
      //Logger.getRootLogger().setLevel(Level.INFO);
      final DbusEventBuffer dbusBuf =
          new DbusEventBuffer(getConfig(1144, 500, 100, 500, AllocationPolicy.HEAP_MEMORY,
                                        QueuePolicy.OVERWRITE_ON_WRITE, AssertLevel.ALL));
      BufferPositionParser parser = dbusBuf.getBufferPositionParser();
      LOG.info("New Batch append 1");
      DbusEventGenerator generator = new DbusEventGenerator();
      Vector<DbusEvent> events = new Vector<DbusEvent>();
      generator.generateEvents(9, 1, 120, 39, events);

      // Add events to the EventBuffer. Now the buffer is full
      DbusEventAppender appender = new DbusEventAppender(events,dbusBuf,null);
      //Logger.getRootLogger().setLevel(Level.ALL);
      appender.run(); // running in the same thread

      LOG.info("Head:" + parser.toString(dbusBuf.getHead()) + ",Tail:" + parser.toString(dbusBuf.getTail()));
      LOG.info("Num buffers :" + dbusBuf.getBuffer().length);
      LOG.info("Buffer :" + Arrays.toString(dbusBuf.getBuffer()));

      long headPos = dbusBuf.getHead();
      long tailPos = dbusBuf.getTail();
      long headGenId = parser.bufferGenId(headPos);
      long headIndexId = parser.bufferIndex(headPos);
      long headOffset = parser.bufferOffset(headPos);
      long tailGenId = parser.bufferGenId(tailPos);
      long tailIndexId = parser.bufferIndex(tailPos);
      long tailOffset = parser.bufferOffset(tailPos);

      assertEquals("Head GenId", 0, headGenId);
      assertEquals("Head Index", 1, headIndexId);
      assertEquals("Head Offset", 222, headOffset);
      assertEquals("Tail GenId", 1, tailGenId);
      assertEquals("Tail Index", 0, tailIndexId);
      assertEquals("Tail Offset", 483, tailOffset);


      LOG.info("New Batch append 2");
      generator = new DbusEventGenerator(100);
      events = new Vector<DbusEvent>();
      generator.generateEvents(1, 1, 80, 10, events);

      // Add events to the EventBuffer. Now the buffer is full
      appender = new DbusEventAppender(events,dbusBuf,null);
      //Logger.getRootLogger().setLevel(Level.ALL);
      appender.run();
      LOG.info("Head:" + parser.toString(dbusBuf.getHead()) + ",Tail:" + parser.toString(dbusBuf.getTail()));
      LOG.info("Num buffers :" + dbusBuf.getBuffer().length);
      LOG.info("Buffer :" + Arrays.toString(dbusBuf.getBuffer()));
      headPos = dbusBuf.getHead();
      tailPos = dbusBuf.getTail();
      headGenId = parser.bufferGenId(headPos);
      headIndexId = parser.bufferIndex(headPos);
      headOffset = parser.bufferOffset(headPos);
      tailGenId = parser.bufferGenId(tailPos);
      tailIndexId = parser.bufferIndex(tailPos);
      tailOffset = parser.bufferOffset(tailPos);
      assertEquals("Head GenId", 0, headGenId);
      assertEquals("Head Index", 1, headIndexId);
      assertEquals("Head Offset", 222, headOffset);
      assertEquals("Tail GenId", 1, tailGenId);
      assertEquals("Tail Index", 1, tailIndexId);
      assertEquals("Tail Offset", 193, tailOffset);


      LOG.info("New Batch append 3");
      generator = new DbusEventGenerator(200);
      events = new Vector<DbusEvent>();
      generator.generateEvents(1, 1, 400, 320, events);

      // Add events to the EventBuffer. Now the buffer is full
      appender = new DbusEventAppender(events,dbusBuf,null);
      //Logger.getRootLogger().setLevel(Level.ALL);
      appender.run();
      LOG.info("Head:" + parser.toString(dbusBuf.getHead()) + ",Tail:" + parser.toString(dbusBuf.getTail()));
      LOG.info("Num buffers :" + dbusBuf.getBuffer().length);
      LOG.info("Buffer :" + Arrays.toString(dbusBuf.getBuffer()));
      headPos = dbusBuf.getHead();
      tailPos = dbusBuf.getTail();
      headGenId = parser.bufferGenId(headPos);
      headIndexId = parser.bufferIndex(headPos);
      headOffset = parser.bufferOffset(headPos);
      tailGenId = parser.bufferGenId(tailPos);
      tailIndexId = parser.bufferIndex(tailPos);
      tailOffset = parser.bufferOffset(tailPos);
      assertEquals("Head GenId", 1, headGenId);
      assertEquals("Head Index", 1, headIndexId);
      assertEquals("Head Offset", 61, headOffset);
      assertEquals("Tail GenId", 2, tailGenId);
      assertEquals("Tail Index", 0, tailIndexId);
      assertEquals("Tail Offset", 442, tailOffset);
    }


    // Single byte-buffer EVB case
    {
      //Logger.getRootLogger().setLevel(Level.INFO);
      final DbusEventBuffer dbusBuf =
          new DbusEventBuffer(getConfig(2144, 5000, 200, 500, AllocationPolicy.HEAP_MEMORY,
                                        QueuePolicy.OVERWRITE_ON_WRITE, AssertLevel.ALL));
      BufferPositionParser parser = dbusBuf.getBufferPositionParser();
      LOG.info("New Batch append 1");
      DbusEventGenerator generator = new DbusEventGenerator();
      Vector<DbusEvent> events = new Vector<DbusEvent>();
      generator.generateEvents(28, 2, 180, 39, events);

      // Add events to the EventBuffer. Now the buffer is full
      DbusEventAppender appender = new DbusEventAppender(events,dbusBuf,null);
      //Logger.getRootLogger().setLevel(Level.ALL);
      appender.run(); // running in the same thread

      LOG.info("Head:" + parser.toString(dbusBuf.getHead()) + ",Tail:" + parser.toString(dbusBuf.getTail()));
      LOG.info("Num buffers :" + dbusBuf.getBuffer().length);
      LOG.info("Buffer :" + Arrays.toString(dbusBuf.getBuffer()));
      long headPos = dbusBuf.getHead();
      long tailPos = dbusBuf.getTail();
      long headGenId = parser.bufferGenId(headPos);
      long headIndexId = parser.bufferIndex(headPos);
      long headOffset = parser.bufferOffset(headPos);
      long tailGenId = parser.bufferGenId(tailPos);
      long tailIndexId = parser.bufferIndex(tailPos);
      long tailOffset = parser.bufferOffset(tailPos);

      assertEquals("Head GenId", 0, headGenId);
      assertEquals("Head Index", 0, headIndexId);
      assertEquals("Head Offset", 1627, headOffset);
      assertEquals("Tail GenId", 1, tailGenId);
      assertEquals("Tail Index", 0, tailIndexId);
      assertEquals("Tail Offset", 1627, tailOffset);

      LOG.info("New Batch append 2");
      generator = new DbusEventGenerator(200);
      events = new Vector<DbusEvent>();
      generator.generateEvents(1, 1, 80, 10, events);

      // Add events to the EventBuffer. Now the buffer is full
      appender = new DbusEventAppender(events,dbusBuf,null);
      //Logger.getRootLogger().setLevel(Level.ALL);
      appender.run();
      LOG.info("Head:" + parser.toString(dbusBuf.getHead()) + ",Tail:" + parser.toString(dbusBuf.getTail()));
      LOG.info("Num buffers :" + dbusBuf.getBuffer().length);
      LOG.info("Buffer :" + Arrays.toString(dbusBuf.getBuffer()));
      headPos = dbusBuf.getHead();
      tailPos = dbusBuf.getTail();
      headGenId = parser.bufferGenId(headPos);
      headIndexId = parser.bufferIndex(headPos);
      headOffset = parser.bufferOffset(headPos);
      tailGenId = parser.bufferGenId(tailPos);
      tailIndexId = parser.bufferIndex(tailPos);
      tailOffset = parser.bufferOffset(tailPos);

      assertEquals("Head GenId", 0, headGenId);
      assertEquals("Head Index", 0, headIndexId);
      assertEquals("Head Offset", 1888, headOffset);
      assertEquals("Tail GenId", 1, tailGenId);
      assertEquals("Tail Index", 0, tailIndexId);
      assertEquals("Tail Offset", 1820, tailOffset);

      LOG.info("New Batch append 3");
      generator = new DbusEventGenerator(300);
      events = new Vector<DbusEvent>();
      generator.generateEvents(1, 1, 400, 330, events);

      // Add events to the EventBuffer. Now the buffer is full
      appender = new DbusEventAppender(events,dbusBuf,null);
      //Logger.getRootLogger().setLevel(Level.ALL);
      appender.run();
      LOG.info("Head:" + parser.toString(dbusBuf.getHead()) + ",Tail:" + parser.toString(dbusBuf.getTail()));
      LOG.info("Num buffers :" + dbusBuf.getBuffer().length);
      LOG.info("Buffer :" + Arrays.toString(dbusBuf.getBuffer()));
      headPos = dbusBuf.getHead();
      tailPos = dbusBuf.getTail();
      headGenId = parser.bufferGenId(headPos);
      headIndexId = parser.bufferIndex(headPos);
      headOffset = parser.bufferOffset(headPos);
      tailGenId = parser.bufferGenId(tailPos);
      tailIndexId = parser.bufferIndex(tailPos);
      tailOffset = parser.bufferOffset(tailPos);

      assertEquals("Head GenId", 1, headGenId);
      assertEquals("Head Index", 0, headIndexId);
      assertEquals("Head Offset", 583, headOffset);
      assertEquals("Tail GenId", 2, tailGenId);
View Full Code Here

TOP

Related Classes of com.linkedin.databus.core.util.BufferPositionParser

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.