Package org.apache.log4j

Examples of org.apache.log4j.Logger$PrivateManager


   * that by rigging MockRelayConnection to call RelayPuller.shutdown() right before responding
   * to requestSources();
   *  */
  public void testShutdownRace() throws Exception
  {
    final Logger log = Logger.getLogger("TestRelayPullThread.testShutdownRace");
    log.setLevel(Level.INFO);
    log.info("start");

    //elaborate test setup
    List<String> sources = Arrays.asList("source1");

    Properties clientProps = new Properties();
    clientProps.setProperty("client.container.httpPort", "0");
    clientProps.setProperty("client.runtime.bootstrap.enabled", "false");
    clientProps.setProperty("client.runtime.relay(1).name", "relay1");
    clientProps.setProperty("client.runtime.relay(1).port", "10001");
    clientProps.setProperty("client.runtime.relay(1).sources", "source1");
    clientProps.setProperty("client.connectionDefaults.eventBuffer.maxSize", "100000");
    clientProps.setProperty("client.connectionDefaults.pullerRetries.maxRetryNum", "9");
    clientProps.setProperty("client.connectionDefaults.pullerRetries.sleepIncFactor", "1.0");
    clientProps.setProperty("client.connectionDefaults.pullerRetries.sleepIncDelta", "1");
    clientProps.setProperty("client.connectionDefaults.pullerRetries.initSleep", "1");


    DatabusHttpClientImpl client = new DatabusHttpClientImpl("client.", clientProps);
    Assert.assertNotNull(client, "client instantiation ok");

    final DatabusHttpClientImpl.StaticConfig clientConf = client.getClientStaticConfig();
    final DatabusSourcesConnection.StaticConfig srcConnConf = clientConf.getConnectionDefaults();

    DatabusHttpClientImpl.RuntimeConfig clientRtConf = clientConf.getRuntime().build();
    DbusEventBuffer.StaticConfig bufferConf = clientConf.getConnectionDefaults().getEventBuffer();

    DbusEventBuffer relayBuffer = new DbusEventBuffer(bufferConf);
    DbusEventBuffer bootstrapBuffer = new DbusEventBuffer(bufferConf);

    //we keep the index of the next server we expect to see
    AtomicInteger serverIdx = new AtomicInteger(-1);

    Set<ServerInfo> relays = clientRtConf.getRelaysSet();

    //generate the order in which we should see the servers
    List<ServerInfo> relayOrder = new ArrayList<ServerInfo>(relays);
    if (LOG.isInfoEnabled())
    {
      StringBuilder sb = new StringBuilder();
      for (ServerInfo serverInfo: relayOrder)
      {
        sb.append(serverInfo.getName());
        sb.append(" ");
      }
      LOG.info("Relay order:" + sb.toString());
    }

    List<IdNamePair> sourcesResponse = new ArrayList<IdNamePair>();
    sourcesResponse.add(new IdNamePair(1L, "source1"));

    RegisterResponseEntry rre1 = new RegisterResponseEntry(1L, (short)1, SCHEMA$.toString());
    final HashMap<Long, List<RegisterResponseEntry>> registerResponse =
        new HashMap<Long, List<RegisterResponseEntry>>();
    registerResponse.put(1L, Arrays.asList(rre1));

    //This guy succeeds on both /sources and /register
    final MockRelayConnection relayConn1 =
        new MockRelayConnection(sourcesResponse,
                                registerResponse,
                                null,
                                serverIdx);
    //This guy will succeed on /sources but will force a shutdown so that
    //the success message is ignored
    final MockRelayConnection relayConn2 =
        new MockRelayConnectionForTestShutdownRace(sourcesResponse,
                                                   null,
                                                   null,
                                                   serverIdx,
                                                   log);


    DatabusRelayConnectionFactory mockConnFactory =
        EasyMock.createMock("mockRelayFactory", DatabusRelayConnectionFactory.class);

    // expected scenario:  create relayConn1 -> /sources success -> /register success ->
    // /stream error -> create relayConn2 -> call /sources -> shut down puller -> return
    // success for /sources
    EasyMock.expect(mockConnFactory.createRelayConnection(
        serverNameMatcher(serverIdx, relayOrder),
        EasyMock.<ActorMessageQueue>notNull(),
        EasyMock.<RemoteExceptionHandler>notNull())).andReturn(relayConn1);
    EasyMock.expect(mockConnFactory.createRelayConnection(
        serverNameMatcher(serverIdx, relayOrder),
        EasyMock.<ActorMessageQueue>notNull(),
        EasyMock.<RemoteExceptionHandler>notNull())).andReturn(relayConn2);

    EasyMock.replay(mockConnFactory);

    List<DatabusSubscription> sourcesSubList = DatabusSubscription.createSubscriptionList(sources);
    //Dummy connection object as expected by the puller thread
    // Note that in this case, it is ok to pass Set<relays> as all the relays serve the same source "source1"
    ConnectionStateFactory connStateFactory = new ConnectionStateFactory(sources);
    DatabusSourcesConnection sourcesConn = new DatabusSourcesConnection(
        srcConnConf, sourcesSubList, relays, null, null, null, relayBuffer, bootstrapBuffer,
        Executors.newCachedThreadPool(), null, null, null, null, null, null, null, mockConnFactory, null,
        null, null, null, new DbusEventV1Factory(), connStateFactory);

    final RelayPullThread relayPuller =
        new RelayPullThread("RelayPuller", sourcesConn, relayBuffer, connStateFactory, relays,
                            new ArrayList<DbusKeyCompositeFilterConfig>(),
                            !clientConf.getRuntime().getBootstrap().isEnabled(),
                            clientConf.isReadLatestScnOnErrorEnabled(),
                            clientConf.getPullerBufferUtilizationPct(),
                            Integer.MAX_VALUE,
                            ManagementFactory.getPlatformMBeanServer(),
                            new DbusEventV1Factory(),
                            null);
    //relayPuller.getLog().setLevel(Level.INFO);
    RemoteExceptionHandler mockRemoteExceptionHandler =
        new MockRemoteExceptionHandler(sourcesConn, relayBuffer, relayPuller);

    Field field = relayPuller.getClass().getDeclaredField("_remoteExceptionHandler");
    field.setAccessible(true);
    field.set(relayPuller, mockRemoteExceptionHandler);

    relayConn1.setCallback(relayPuller);
    relayConn2.setCallback(relayPuller);

    //Let the show begin
    final Thread relayPullerThread = new Thread(relayPuller, "testShutdownRace.RelayPuller");
    relayPullerThread.setDaemon(true);
    relayPullerThread.start();

    relayPuller.enqueueMessage(LifecycleMessage.createStartMessage());

    //wait for the puller to go the STREAM_REQUEST_SUCCESS state
    TestUtil.assertWithBackoff(new ConditionCheck()
    {
      @Override
      public boolean check()
      {
        return null != relayConn1.getLastStateMsg();
      }
    }, "wait for call from the puller to the relay connection", 500, log);

    //wait for puller thread to shutdown
    TestUtil.assertWithBackoff(new ConditionCheck()
    {
      @Override
      public boolean check()
      {
        log.debug(relayPuller.getMessageHistoryLog());
        return !relayPullerThread.isAlive();
      }
    }, "wait for puller to shutdown", 1000, log);

    EasyMock.verify(mockConnFactory);
    Assert.assertEquals(relayPuller.getLastOpenConnection(), null);

    log.info("done");
  }
View Full Code Here


  {
    // create a temp logger with simplified message
    //PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
    PatternLayout defaultLayout = new PatternLayout("%m%n");
    ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
    Logger newLog = Logger.getLogger("Simple");
    newLog.removeAllAppenders();
    newLog.addAppender(defaultAppender);
    newLog.setAdditivity(false);
    newLog.setLevel(Level.ALL);

    log.log(l, toString());
    if (!isEnabled())
    {
      log.log(l, "ScnIndex is disabled");
      return;
    }

    // consolidated printing:
    //     beginBlock-endBlock:SCN=>Offset
    // actual line is printed only when offset changes
    long currentOffset, beginBlock;
    long  endBlock;
    long currentScn = -1;
    currentOffset = -1;
    endBlock = beginBlock = 0;
    newLog.log(l, "logger name: " + log.getName() + " ts:" + (new Date()));
    for (int position = 0; position < buffer.limit();  position += SIZE_OF_SCN_OFFSET_RECORD)
    {
      long nextOffset = getOffset(position);
      if (currentOffset < 0) currentOffset = nextOffset;
      long nextBlock = position/SIZE_OF_SCN_OFFSET_RECORD;
      long nextScn = getScn(position);
      if (currentScn < 0) currentScn = nextScn;
      if(nextOffset != currentOffset || currentScn != nextScn) {
        // new offset - print the previous line
        newLog.log(l, buildBlockIndexString(beginBlock, endBlock, currentScn, currentOffset));

        currentOffset = nextOffset;
        beginBlock = nextBlock;
        currentScn = nextScn;
      }

      endBlock = nextBlock;

      //log.log(p, i/SIZE_OF_SCN_OFFSET_RECORD + ":" + nextScn + "->" + nextOffset);
    }
    // final line
    newLog.log(l, buildBlockIndexString(beginBlock, endBlock, currentScn, currentOffset));
  }
View Full Code Here

    }

    @Test(groups = {"small", "functional"})
    public void testOneWindowTwoGroupedConsumersHappyPath()
    {
      final Logger log = Logger.getLogger("TestGenericDispatcher.testOneWindowTwoGroupedConsumersHappyPath");
      log.info("start");
        int source1EventsNum = 2;
        int source2EventsNum = 2;

        Hashtable<Long, AtomicInteger> keyCounts = new Hashtable<Long, AtomicInteger>();
        Hashtable<Short, AtomicInteger> srcidCounts = new Hashtable<Short, AtomicInteger>();

        final TestGenericDispatcherEventBuffer eventsBuf =
            new TestGenericDispatcherEventBuffer(_generic100KBufferStaticConfig);
        eventsBuf.start(0);
        eventsBuf.startEvents();
        initBufferWithEvents(eventsBuf, 1, source1EventsNum, (short)1, keyCounts, srcidCounts);
        initBufferWithEvents(eventsBuf, 1 + source1EventsNum, source2EventsNum, (short)2, keyCounts,
                srcidCounts);
        eventsBuf.endEvents(100L);

        DatabusStreamConsumer mockConsumer =
                new EventCountingConsumer(new StateVerifyingStreamConsumer(null), keyCounts, srcidCounts);
        DatabusStreamConsumer mockConsumer2 =
                new EventCountingConsumer(new StateVerifyingStreamConsumer(null), keyCounts, srcidCounts);

        DatabusCombinedConsumer sdccMockConsumer = new SelectingDatabusCombinedConsumer(mockConsumer);
        DatabusCombinedConsumer sdccMockConsumer2 = new SelectingDatabusCombinedConsumer(mockConsumer2);

        List<String> sources = new ArrayList<String>();
        Map<Long, IdNamePair> sourcesMap = new HashMap<Long, IdNamePair>();
        for (int i = 1; i <= 3; ++i)
        {
            IdNamePair sourcePair = new IdNamePair((long)i, "source" + i);
            sources.add(sourcePair.getName());
            sourcesMap.put(sourcePair.getId(), sourcePair);
        }

        DatabusV2ConsumerRegistration consumerReg =
                new DatabusV2ConsumerRegistration(Arrays.asList(sdccMockConsumer, sdccMockConsumer2),
                        sources, null);

        List<DatabusV2ConsumerRegistration> allRegistrations =
                Arrays.asList(consumerReg);
        MultiConsumerCallback callback =
                new MultiConsumerCallback(
                        allRegistrations,
                        Executors.newFixedThreadPool(2),
                        1000,
                        new StreamConsumerCallbackFactory(null, null),
                        null,
                        null,
                        null,
                        null);
        callback.setSourceMap(sourcesMap);

        List<DatabusSubscription> subs = DatabusSubscription.createSubscriptionList(sources);
        RelayDispatcher dispatcher =
                new RelayDispatcher("dispatcher", _genericRelayConnStaticConfig, subs,
                        new InMemoryPersistenceProvider(),
                        eventsBuf, callback, null, null,null,null, null);

        Thread dispatcherThread = new Thread(dispatcher);
        //dispatcherThread.setDaemon(true);
        dispatcherThread.start();

        HashMap<Long, List<RegisterResponseEntry>> schemaMap =
                new HashMap<Long, List<RegisterResponseEntry>>();

        List<RegisterResponseEntry> l1 = new ArrayList<RegisterResponseEntry>();
        List<RegisterResponseEntry> l2 = new ArrayList<RegisterResponseEntry>();
        List<RegisterResponseEntry> l3 = new ArrayList<RegisterResponseEntry>();

        l1.add(new RegisterResponseEntry(1L, (short)1,SOURCE1_SCHEMA_STR));
        l2.add(new RegisterResponseEntry(2L, (short)1,SOURCE2_SCHEMA_STR));
        l3.add(new RegisterResponseEntry(3L, (short)1,SOURCE3_SCHEMA_STR));

        schemaMap.put(1L, l1);
        schemaMap.put(2L, l2);
        schemaMap.put(3L, l3);

        dispatcher.enqueueMessage(SourcesMessage.createSetSourcesIdsMessage(sourcesMap.values()));
        dispatcher.enqueueMessage(SourcesMessage.createSetSourcesSchemasMessage(schemaMap));

        try
        {
            Thread.sleep(2000);
        }
        catch (InterruptedException ie) {}

        dispatcher.shutdown();

        for (long i = 1; i <= source1EventsNum + source2EventsNum; ++i)
        {
            assertEquals("correct amount of callbacks for key " + i, 1, keyCounts.get(i).intValue());
        }

        assertEquals("correct amount of callbacks for srcid 1", source1EventsNum,
                srcidCounts.get((short)1).intValue());
        assertEquals("correct amount of callbacks for srcid 2", source2EventsNum,
                srcidCounts.get((short)2).intValue());
        verifyNoLocks(null, eventsBuf);
        log.info("end\n");
    }
View Full Code Here

    }

    @Test(groups = {"small", "functional"})
    public void testTwoWindowEventCallbackFailure()
    {
      final Logger log = Logger.getLogger("TestGenericDispatcher.testTwoWindowEventCallbackFailure");
      log.info("start");
        int source1EventsNum = 2;
        int source2EventsNum = 2;

        Hashtable<Long, AtomicInteger> keyCounts = new Hashtable<Long, AtomicInteger>();
        Hashtable<Short, AtomicInteger> srcidCounts = new Hashtable<Short, AtomicInteger>();

        final TestGenericDispatcherEventBuffer eventsBuf =
            new TestGenericDispatcherEventBuffer(_generic100KBufferStaticConfig);
        eventsBuf.start(0);
        eventsBuf.startEvents();
        initBufferWithEvents(eventsBuf, 1, source1EventsNum, (short)1, keyCounts, srcidCounts);
        eventsBuf.endEvents(100L);
        eventsBuf.startEvents();
        initBufferWithEvents(eventsBuf, 1 + source1EventsNum, source2EventsNum, (short)2, keyCounts, srcidCounts);
        eventsBuf.endEvents(200L);

        DatabusStreamConsumer mockConsumer =
                new EventCountingConsumer(
                        new StateVerifyingStreamConsumer(
                                new DataEventFailingStreamConsumer((short)2)), keyCounts, srcidCounts);
        SelectingDatabusCombinedConsumer sdccMockConsumer = new SelectingDatabusCombinedConsumer(mockConsumer);

        List<String> sources = new ArrayList<String>();
        Map<Long, IdNamePair> sourcesMap = new HashMap<Long, IdNamePair>();
        for (int i = 1; i <= 3; ++i)
        {
            IdNamePair sourcePair = new IdNamePair((long)i, "source" + i);
            sources.add(sourcePair.getName());
            sourcesMap.put(sourcePair.getId(), sourcePair);
        }

        DatabusV2ConsumerRegistration consumerReg =
                new DatabusV2ConsumerRegistration(sdccMockConsumer, sources, null);

        List<DatabusV2ConsumerRegistration> allRegistrations =
                Arrays.asList(consumerReg);
        MultiConsumerCallback callback =
                new MultiConsumerCallback(
                        allRegistrations,
                        Executors.newSingleThreadExecutor(),
                        1000,
                        new StreamConsumerCallbackFactory(null, null),
                        null,
                        null,
                        null,
                        null);
        callback.setSourceMap(sourcesMap);

        List<DatabusSubscription> subs = DatabusSubscription.createSubscriptionList(sources);
        RelayDispatcher dispatcher =
                new RelayDispatcher("dispatcher", _genericRelayConnStaticConfig, subs,
                        new InMemoryPersistenceProvider(),
                        eventsBuf, callback, null,null,null,null, null);

        Thread dispatcherThread = new Thread(dispatcher);
        //dispatcherThread.setDaemon(true);
        dispatcherThread.start();

        HashMap<Long, List<RegisterResponseEntry>> schemaMap =
                new HashMap<Long, List<RegisterResponseEntry>>();

        List<RegisterResponseEntry> l1 = new ArrayList<RegisterResponseEntry>();
        List<RegisterResponseEntry> l2 = new ArrayList<RegisterResponseEntry>();
        List<RegisterResponseEntry> l3 = new ArrayList<RegisterResponseEntry>();

        l1.add(new RegisterResponseEntry(1L, (short)1,SOURCE1_SCHEMA_STR));
        l2.add(new RegisterResponseEntry(2L, (short)1,SOURCE2_SCHEMA_STR));
        l3.add(new RegisterResponseEntry(3L, (short)1,SOURCE3_SCHEMA_STR));

        schemaMap.put(1L, l1);
        schemaMap.put(2L, l2);
        schemaMap.put(3L, l3);

        dispatcher.enqueueMessage(SourcesMessage.createSetSourcesIdsMessage(sourcesMap.values()));
        dispatcher.enqueueMessage(SourcesMessage.createSetSourcesSchemasMessage(schemaMap));

        try
        {
            Thread.sleep(2000);
        }
        catch (InterruptedException ie) {}

        dispatcher.shutdown();

        for (long i = 1; i <= source1EventsNum; ++i)
        {
            assertEquals("correct amount of callbacks for key " + i,
                    1, keyCounts.get(i).intValue());
        }

        for (long i = source2EventsNum + 1; i <= source1EventsNum + source2EventsNum; ++i)
        {
            assert keyCounts.get(1L + source1EventsNum).intValue() > 1 :
                "correct amount of callbacks for key " + i + ":" + keyCounts.get(i).intValue();
        }
        verifyNoLocks(null, eventsBuf);
        log.info("end\n");
    }
View Full Code Here


    @Test(groups = {"small", "functional"})
    public void testTwoWindowEventIndependentConsumersCallbackFailure()
    {
      final Logger log = Logger.getLogger("TestGenericDispatcher.testTwoWindowEventIndependentConsumersCallbackFailure");
      log.info("start");
        int source1EventsNum = 4;
        int source2EventsNum = 5;

        Hashtable<Long, AtomicInteger> keyCounts = new Hashtable<Long, AtomicInteger>();
        Hashtable<Short, AtomicInteger> srcidCounts = new Hashtable<Short, AtomicInteger>();

        final TestGenericDispatcherEventBuffer eventsBuf =
            new TestGenericDispatcherEventBuffer(_generic100KBufferStaticConfig);
        eventsBuf.start(0);
        eventsBuf.startEvents();
        initBufferWithEvents(eventsBuf, 1, source1EventsNum, (short)1, keyCounts, srcidCounts);
        eventsBuf.endEvents(100L);
        eventsBuf.startEvents();
        initBufferWithEvents(eventsBuf, 1 + source1EventsNum, source2EventsNum, (short)2, keyCounts, srcidCounts);
        eventsBuf.endEvents(200L);

        DatabusStreamConsumer mockConsumer =
                new EventCountingConsumer(
                        new StateVerifyingStreamConsumer(
                                new DataSourceFailingStreamConsumer("source2")),
                                keyCounts, srcidCounts);
        SelectingDatabusCombinedConsumer sdccMockConsumer = new SelectingDatabusCombinedConsumer(mockConsumer);

        Hashtable<Long, AtomicInteger> keyCounts2 = new Hashtable<Long, AtomicInteger>();
        Hashtable<Short, AtomicInteger> srcidCounts2 = new Hashtable<Short, AtomicInteger>();
        for (Long key: keyCounts.keySet())
        {
            keyCounts2.put(key, new AtomicInteger(0));
        }
        for (Short srcid: srcidCounts.keySet())
        {
            srcidCounts2.put(srcid, new AtomicInteger(0));
        }

        DatabusStreamConsumer mockConsumer2 =
                new EventCountingConsumer(new StateVerifyingStreamConsumer(null),
                        keyCounts2, srcidCounts2);
        SelectingDatabusCombinedConsumer sdccMockConsumer2 = new SelectingDatabusCombinedConsumer(mockConsumer2);

        List<String> sources = new ArrayList<String>();
        Map<Long, IdNamePair> sourcesMap = new HashMap<Long, IdNamePair>();
        for (int i = 1; i <= 3; ++i)
        {
            IdNamePair sourcePair = new IdNamePair((long)i, "source" + i);
            sources.add(sourcePair.getName());
            sourcesMap.put(sourcePair.getId(), sourcePair);
        }

        DatabusV2ConsumerRegistration consumerReg =
                new DatabusV2ConsumerRegistration(sdccMockConsumer, sources, null);

        DatabusV2ConsumerRegistration consumerReg2 =
                new DatabusV2ConsumerRegistration(sdccMockConsumer2, sources, null);
        List<DatabusV2ConsumerRegistration> allRegistrations =
                Arrays.asList(consumerReg, consumerReg2);
        MultiConsumerCallback callback =
                new MultiConsumerCallback(
                        allRegistrations,
                        Executors.newSingleThreadExecutor(),
                        1000,
                        new StreamConsumerCallbackFactory(null, null),
                        null,
                        null,
                        null,
                        null);
        callback.setSourceMap(sourcesMap);

        List<DatabusSubscription> subs = DatabusSubscription.createSubscriptionList(sources);
        RelayDispatcher dispatcher =
                new RelayDispatcher("dispatcher", _genericRelayConnStaticConfig, subs,
                        new InMemoryPersistenceProvider(),
                        eventsBuf, callback, null,null,null,null, null);

        Thread dispatcherThread = new Thread(dispatcher);
        //dispatcherThread.setDaemon(true);
        dispatcherThread.start();

        HashMap<Long, List<RegisterResponseEntry>> schemaMap =
                new HashMap<Long, List<RegisterResponseEntry>>();

        List<RegisterResponseEntry> l1 = new ArrayList<RegisterResponseEntry>();
        List<RegisterResponseEntry> l2 = new ArrayList<RegisterResponseEntry>();
        List<RegisterResponseEntry> l3 = new ArrayList<RegisterResponseEntry>();

        l1.add(new RegisterResponseEntry(1L, (short)1,SOURCE1_SCHEMA_STR));
        l2.add(new RegisterResponseEntry(2L, (short)1,SOURCE2_SCHEMA_STR));
        l3.add(new RegisterResponseEntry(3L, (short)1,SOURCE3_SCHEMA_STR));

        schemaMap.put(1L, l1);
        schemaMap.put(2L, l2);
        schemaMap.put(3L, l3);

        dispatcher.enqueueMessage(SourcesMessage.createSetSourcesIdsMessage(sourcesMap.values()));
        dispatcher.enqueueMessage(SourcesMessage.createSetSourcesSchemasMessage(schemaMap));

        try
        {
            Thread.sleep(2000);
        }
        catch (InterruptedException ie) {}

        dispatcher.shutdown();

        for (long i = 1; i <= source1EventsNum; ++i)
        {
            assertEquals("correct amount of callbacks for key " + i,
                    1, keyCounts.get(i).intValue());
            assertEquals("correct amount of callbacks for key " + i,
                    1, keyCounts2.get(i).intValue());
        }

        for (long i = source2EventsNum + 1; i <= source1EventsNum + source2EventsNum; ++i)
        {
            assert keyCounts.get(1L + source1EventsNum).intValue() == 0 :
                "correct amount of callbacks for key " + i + ":" + keyCounts.get(i).intValue();
        }
        verifyNoLocks(null, eventsBuf);
        log.info("end\n");
    }
View Full Code Here


    @Test(groups = {"small", "functional"})
    public void testLargeWindowCheckpointFrequency() throws Exception
    {
      final Logger log = Logger.getLogger("TestGenericDispatcher.testLargeWindowCheckpointFrequency");
      log.info("start");
            /* Consumer creation */
            int timeTakenForEventInMs = 1;
            DatabusStreamConsumer tConsumer = new TimeoutTestConsumer(timeTakenForEventInMs);
            DatabusCombinedConsumer sdccTConsumer = new SelectingDatabusCombinedConsumer(tConsumer);
            HashMap<Long, List<RegisterResponseEntry>> schemaMap =
                    new HashMap<Long, List<RegisterResponseEntry>>();

            short srcId=1;
            List<RegisterResponseEntry> l1 = new ArrayList<RegisterResponseEntry>();
            l1.add(new RegisterResponseEntry(1L, srcId,SOURCE1_SCHEMA_STR));

            schemaMap.put(1L, l1);

            Map<Long, IdNamePair> sourcesMap = new HashMap<Long, IdNamePair>();
            List<String> sources = new ArrayList<String>();
            for (int i = 1; i <= 1; ++i)
            {
                IdNamePair sourcePair = new IdNamePair((long)i, "source" + i);
                sources.add(sourcePair.getName());
                sourcesMap.put(sourcePair.getId(), sourcePair);
            }

            DatabusV2ConsumerRegistration consumerReg = new DatabusV2ConsumerRegistration(sdccTConsumer, sources, null);
            List<DatabusV2ConsumerRegistration> allRegistrations =  Arrays.asList(consumerReg);
            MultiConsumerCallback mConsumer = new MultiConsumerCallback(allRegistrations,Executors.newFixedThreadPool(2),
                    1000, new StreamConsumerCallbackFactory(null, null), null, null, null, null);

            /* Source configuration */
            double thresholdChkptPct = 50.0;
            DatabusSourcesConnection.Config conf = new DatabusSourcesConnection.Config();
            conf.setCheckpointThresholdPct(thresholdChkptPct);
            DatabusSourcesConnection.StaticConfig connConfig = conf.build();

            /* Generate events **/
            Vector<DbusEvent> srcTestEvents = new Vector<DbusEvent>();
            Vector<Short> srcIdList = new Vector<Short> ();
            srcIdList.add(srcId);
            int numEvents = 100;
            int payloadSize = 20;
            int maxWindowSize = 80;
            DbusEventGenerator evGen = new DbusEventGenerator(0,srcIdList);
            Assert.assertTrue(evGen.generateEvents(numEvents, maxWindowSize, 512, payloadSize, srcTestEvents) > 0);

            int size=0;
            for (DbusEvent e : srcTestEvents)
            {
                if (!e.isControlMessage()) {
                    size = e.size();
                    break;
                }
            }

            //make buffer large enough to hold data
            int producerBufferSize = (int) (numEvents*size*1.1);
            int individualBufferSize = producerBufferSize;
            int indexSize = producerBufferSize / 10;
            int stagingBufferSize = producerBufferSize;

            /*Event Buffer creation */
            final TestGenericDispatcherEventBuffer dataEventsBuffer=
                new TestGenericDispatcherEventBuffer(
                    getConfig(producerBufferSize, individualBufferSize, indexSize ,
                              stagingBufferSize, AllocationPolicy.HEAP_MEMORY,QueuePolicy.BLOCK_ON_WRITE));

            List<DatabusSubscription> subs = DatabusSubscription.createSubscriptionList(sources);
            /* Generic Dispatcher creation */
            TestDispatcher<DatabusCombinedConsumer> dispatcher = new TestDispatcher<DatabusCombinedConsumer>("freqCkpt",
                    connConfig,
                    subs,
                    new InMemoryPersistenceProvider(),
                    dataEventsBuffer,
                    mConsumer,
                    true);

            /* Launch writer */
            DbusEventAppender eventProducer = new DbusEventAppender(srcTestEvents, dataEventsBuffer, null) ;
            Thread tEmitter = new Thread(eventProducer);
            tEmitter.start();
            tEmitter.join();

            /* Launch dispatcher */
            Thread tDispatcher = new Thread(dispatcher);
            tDispatcher.start();

            /* Now initialize this damn state machine */
            dispatcher.enqueueMessage(SourcesMessage.createSetSourcesIdsMessage(sourcesMap.values()));
            dispatcher.enqueueMessage(SourcesMessage.createSetSourcesSchemasMessage(schemaMap));

            Thread.sleep(2000);

            System.out.println("Number of checkpoints = " + dispatcher.getNumCheckPoints());
            Assert.assertTrue(dispatcher.getNumCheckPoints()==3);
            dispatcher.shutdown();
            verifyNoLocks(null, dataEventsBuffer);
        log.info("end\n");
    }
View Full Code Here

    }

    @Test(groups = {"small", "functional"})
    public void testControlEventsRemoval() throws Exception
    {
      final Logger log = Logger.getLogger("TestGenericDispatcher.testControlEventsRemoval");
      log.info("start");
        //DDSDBUS-559
            /* Consumer creation */
            int timeTakenForEventInMs = 10;
            TimeoutTestConsumer tConsumer = new TimeoutTestConsumer(timeTakenForEventInMs);
            HashMap<Long, List<RegisterResponseEntry>> schemaMap =
                    new HashMap<Long, List<RegisterResponseEntry>>();

            short srcId=1;
            List<RegisterResponseEntry> l1 = new ArrayList<RegisterResponseEntry>();
            l1.add(new RegisterResponseEntry(1L, srcId,SOURCE1_SCHEMA_STR));

            schemaMap.put(1L, l1);

            Map<Long, IdNamePair> sourcesMap = new HashMap<Long, IdNamePair>();
            List<String> sources = new ArrayList<String>();
            for (int i = 1; i <= 1; ++i)
            {
                IdNamePair sourcePair = new IdNamePair((long)i, "source" + i);
                sources.add(sourcePair.getName());
                sourcesMap.put(sourcePair.getId(), sourcePair);
            }

            DatabusV2ConsumerRegistration consumerReg = new DatabusV2ConsumerRegistration(tConsumer, sources, null);
            List<DatabusV2ConsumerRegistration> allRegistrations =  Arrays.asList(consumerReg);
            MultiConsumerCallback mConsumer = new MultiConsumerCallback(allRegistrations,Executors.newFixedThreadPool(2),
                    1000, new StreamConsumerCallbackFactory(null, null), null, null, null, null);

            /* Source configuration */
            double thresholdChkptPct = 10.0;
            DatabusSourcesConnection.Config conf = new DatabusSourcesConnection.Config();
            conf.setCheckpointThresholdPct(thresholdChkptPct);
            int freeBufferThreshold = conf.getFreeBufferThreshold();
            DatabusSourcesConnection.StaticConfig connConfig = conf.build();

            /* Generate events **/
            Vector<DbusEvent> srcTestEvents = new Vector<DbusEvent>();
            Vector<Short> srcIdList = new Vector<Short> ();
            srcIdList.add(srcId);
            int numEvents = 100;
            int payloadSize = 20;
            int maxWindowSize =1;
            DbusEventGenerator evGen = new DbusEventGenerator(0,srcIdList);
            Assert.assertTrue(evGen.generateEvents(numEvents, maxWindowSize, payloadSize+62, payloadSize, srcTestEvents) > 0);

            long lastWindowScn = srcTestEvents.get(srcTestEvents.size()-1).sequence();
            int size = 0;
            for (DbusEvent e : srcTestEvents)
            {
                if (e.size() > size) size = e.size();
            }

            //make buffer large enough to hold data
            int numWindows = (numEvents/maxWindowSize) + 1;
            int producerBufferSize = (numEvents+numWindows)*size + freeBufferThreshold;
            int individualBufferSize = producerBufferSize;
            int indexSize = producerBufferSize / 10;
            int stagingBufferSize = producerBufferSize;

            /*Event Buffer creation */
            final TestGenericDispatcherEventBuffer dataEventsBuffer=
                new TestGenericDispatcherEventBuffer(
                    getConfig(producerBufferSize, individualBufferSize, indexSize ,
                              stagingBufferSize, AllocationPolicy.HEAP_MEMORY,
                              QueuePolicy.BLOCK_ON_WRITE));

            List<DatabusSubscription> subs = DatabusSubscription.createSubscriptionList(sources);
            /* Generic Dispatcher creation */
            TestDispatcher<DatabusCombinedConsumer> dispatcher = new TestDispatcher<DatabusCombinedConsumer>("freqCkpt",
                    connConfig,
                    subs,
                    new InMemoryPersistenceProvider(),
                    dataEventsBuffer,
                    mConsumer,
                    true);

            /* Launch writer */
            /* write events all of which  are empty windows */
            DbusEventAppender eventProducer = new DbusEventAppender(srcTestEvents, dataEventsBuffer, null,1.0,true,0) ;
            Thread tEmitter = new Thread(eventProducer);
            tEmitter.start();
            tEmitter.join();
            long freeSpaceBefore = dataEventsBuffer.getBufferFreeSpace();
            /* Launch dispatcher */
            Thread tDispatcher = new Thread(dispatcher);
            tDispatcher.start();

            /* Now initialize  state machine */
            dispatcher.enqueueMessage(SourcesMessage.createSetSourcesIdsMessage(sourcesMap.values()));
            dispatcher.enqueueMessage(SourcesMessage.createSetSourcesSchemasMessage(schemaMap));

            tDispatcher.join(5000);
            LOG.warn("Free Space After=" + dataEventsBuffer.getBufferFreeSpace() +
                     " tConsumer=" + tConsumer + " expected last window=" + lastWindowScn +
                     " last Window = " + dataEventsBuffer.lastWrittenScn());

            Assert.assertTrue(dataEventsBuffer.lastWrittenScn()==lastWindowScn);
            Assert.assertTrue(freeSpaceBefore < dataEventsBuffer.getBufferFreeSpace());

            dispatcher.shutdown();
            verifyNoLocks(null, dataEventsBuffer);
        log.info("end\n");
    }
View Full Code Here


    @Test(groups = {"small", "functional"})
    public void testRollback() throws Exception
    {
      final Logger log = Logger.getLogger("TestGenericDispatcher.testRollback");
      log.info("start");
        //runDispatcherRollback(int numEvents,int maxWindowSize,int numFailDataEvent,int numFailCheckpointEvent,int numFailEndWindow)

        //data event failure rollbacks
        runDispatcherRollback(100, 20, 99, 0,0);
        runDispatcherRollback(100,20,3,0,0);

        //checkpoint event failure
        runDispatcherRollback(100,20,0,1,0);
        runDispatcherRollback(100,20,0,3,0);

        //mixed mode: fail checkpoint event in window 2, but fail 45th event
        runDispatcherRollback(100,20,45,2,0);
        runDispatcherRollback(100,20,45,1,0);

        //endofWindow event failure
        runDispatcherRollback(100,20,0,0,1);
        runDispatcherRollback(100,20,0,0,3);

        //mixed mode: fail checkpoint and fail subsequent end of window
        runDispatcherRollback(100,20,50,2,3);

        //large window recoverable failure
        runDispatcherRollback(100,40,55,0,0,10.0);


        //large window unrecoverable failure : fail first checkpoint
         runDispatcherRollback(100,80,0,1,1,30.0,true,1,0);

        //onCheckpoint always returns null; forces removal of events; but lastSuccessful iterator is null; DDSDBUS-653
        runDispatcherRollback(100,120,0,-2,0,10.0);

        //recoverable failure - DDSDBUS-1659 : with successive rollbacks ;fail before first checkpoint; fail twice; ensure that
        //rollback is triggered twice; and iterators are found in buffer to rollback to
        runDispatcherRollback(100,20,7,0,0,10.0,false,2,0);

        //bootstrap sends control events that are not end-of-window; ensure that rollback logic works with them - DDSDBUS-1776
        runDispatcherRollback(100,10,18,0,0,1.8,false,1,2);

       //negative test: bootstrap sends control events that are not end-of-window;
        // onCheckpoint returns false on first system event; however - that window is sufficient to trigger flush
        // then a subsequent data event failure triggers a rollBack attempt - that fails due to iterator invalidation
        runDispatcherRollback(100,10,18,1,0,1.8,true,1,2);

        log.info("end\n");
    }
View Full Code Here

    }

    @Test
    public void testBootstrapBufferCorruption() throws Exception
    {
      final Logger log = Logger.getLogger("TestGenericDispatcher.testBootstrapBufferCorruption");
      log.info("start");
        //bootstrap event buffer corruption - DDSDBUS-1820
        //try and get the call to flush forcibly on a control-event ; wrap around the buffer
        runDispatcherRollback(100,5,0,0,0,2.0,false,0,2,100,5,true);
        log.info("end\n");
    }
View Full Code Here

    }

    @Test
    public void testNumConsumerErrorsMetric() throws Exception
    {
      final Logger log = Logger.getLogger("TestGenericDispatcher.testNumConsumerErrorsMetric");
      log.info("start");

      // UnifiedClientStats - DDSDBUS-2815
      int numEvents = 100;
      int maxWindowSize = 10;
      int numFailDataEvent = 17// every 17th onDataEvent() call (including retries after rollback!), with total of 3
      int numFailCheckpointEvent = 0;
      int numFailEndWindow = 0;
      double thresholdPct = 90.0;
      boolean negativeTest = false;
      int numFailures = 3;
      int bootstrapCheckpointsPerWindow = 0;
      long timeTakenForDataEventInMs = 1;
      long timeTakenForControlEventInMs = 1;
      boolean wrapAround = false;

      runDispatcherRollback(numEvents, maxWindowSize, numFailDataEvent, numFailCheckpointEvent, numFailEndWindow,
                            thresholdPct, negativeTest, numFailures, bootstrapCheckpointsPerWindow,
                            timeTakenForDataEventInMs, timeTakenForControlEventInMs, wrapAround);

      log.info("end\n");
    }
View Full Code Here

TOP

Related Classes of org.apache.log4j.Logger$PrivateManager

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.