@Test
public void testSessionIdGeneration() throws Exception
{

  class IdGeneratorThread implements Runnable
  {
    private final DbusEventBuffer.SessionIdGenerator _idGenerator;
    private final int _nTimes;
    private final String _ids[];
    public IdGeneratorThread(DbusEventBuffer.SessionIdGenerator idGenerator, int nTimes)
    {
      _idGenerator = idGenerator;
      _nTimes = nTimes;
      _ids = new String[_nTimes];
    }
    @Override
    public void run()
    {
      for (int i = 0; i < _nTimes; i++)
      {
        _ids[i] = _idGenerator.generateSessionId();
      }
      for (int i = 0; i < _nTimes; i++)
      {
        try
        {
          addId(_ids[i]);
        }
        catch (Exception e)
        {
          throw new RuntimeException("Could not add Id" + _ids[i]);
        }
      }
      thrCounter.decrementAndGet();
    }
  }
  final int nThreads = 20;
  final int nTimes = 300;
  final Thread threads[] = new Thread[nThreads];
  final DbusEventBuffer.SessionIdGenerator idGenerator = new DbusEventBuffer.SessionIdGenerator();
  for (int i = 0; i < nThreads; i++)
  {
    threads[i] = new Thread(new IdGeneratorThread(idGenerator, nTimes), "idgen_thread_" + i);
  }
  thrCounter.set(nThreads);
  for (int i = 0; i < nThreads; i++)
  {
    threads[i].start();
  }
  for (int i = 0; i < nThreads; i++)
  {
    threads[i].join();
  }
  Assert.assertEquals(0, thrCounter.get());
}