public static int upperBound(Object[] array, int size, Long value) {
        int left = 0;
        int right = size - 1;
        while (left < right) {
            int middle = left + ((right - left) >> 1);
            if (value >= ((JournalObserver) array[middle]).getTargetJournalVersion()) {
                left = middle + 1;
            } else {
                right = middle - 1;
            }
        }
        if (right == -1) {
            return 0;
        }
        Long rightValue = ((JournalObserver) array[right]).getTargetJournalVersion();
        return value >= rightValue ? right + 1 : right;
    }
@Test
    public void testUpperBound() {
        Multiset<JournalObserver> elements = TreeMultiset.create();
        JournalObserver ovserver2 = new JournalObserver(2L);
        JournalObserver ovserver4 = new JournalObserver(4L);
        JournalObserver ovserver41 = new JournalObserver(4L);
        JournalObserver ovserver42 = new JournalObserver(4L);
        JournalObserver ovserver6 = new JournalObserver(6L);

        // empty
        {
            Assert.assertEquals(0, JournalObservable.upperBound(elements.toArray(), 0, 1L));
        }

        // one element
        {
            elements.add(ovserver2);
            int size = elements.size();
            Assert.assertEquals(0, JournalObservable.upperBound(elements.toArray(), size, 1L));
            Assert.assertEquals(1, JournalObservable.upperBound(elements.toArray(), size, 2L));
            Assert.assertEquals(1, JournalObservable.upperBound(elements.toArray(), size, 3L));
        }

        // same element
        {
            elements.clear();
            elements.add(ovserver2);
            elements.add(ovserver6);
            elements.add(ovserver4);
            elements.add(ovserver41);
            elements.add(ovserver42);

            for (JournalObserver journalObserver : elements) {
                System.out.println(journalObserver);
            }

            int size = elements.size();
            Assert.assertEquals(0, JournalObservable.upperBound(elements.toArray(), size, 1L));
            Assert.assertEquals(1, JournalObservable.upperBound(elements.toArray(), size, 2L));
            Assert.assertEquals(1, JournalObservable.upperBound(elements.toArray(), size, 3L));
            Assert.assertEquals(4, JournalObservable.upperBound(elements.toArray(), size, 4L));
            elements.remove(ovserver41);
            Assert.assertEquals(3, JournalObservable.upperBound(elements.toArray(), elements.size(), 4L));
            elements.remove(ovserver4);
            Assert.assertEquals(2, JournalObservable.upperBound(elements.toArray(), elements.size(), 4L));
            elements.remove(ovserver42);
            Assert.assertEquals(1, JournalObservable.upperBound(elements.toArray(), elements.size(), 4L));
        }

        // same element 2
        {
            elements.clear();
            elements.add(ovserver4);
            elements.add(ovserver41);

            int size = elements.size();
            Assert.assertEquals(2, JournalObservable.upperBound(elements.toArray(), size, 4L));
            elements.remove(ovserver41);
            Assert.assertEquals(1, JournalObservable.upperBound(elements.toArray(), elements.size(), 4L));
            elements.remove(ovserver4);
            Assert.assertEquals(0, JournalObservable.upperBound(elements.toArray(), elements.size(), 4L));
        }

        // odd elements
        {
            elements.clear();
            elements.add(ovserver2);
            elements.add(ovserver2);
            elements.add(ovserver4);
            elements.add(ovserver4);
            elements.add(ovserver6);
            elements.add(ovserver6);
            int size = elements.size();
            //            System.out.println("size=" + size);
            //            for(int i = 0; i < size; i ++) {
            //                System.out.println("array " + i + " = " + ((MasterOpExecutor)elements.get(i)).getTargetJournalId());
            //            }
            Assert.assertEquals(0, JournalObservable.upperBound(elements.toArray(), size, 1L));
            Assert.assertEquals(2, JournalObservable.upperBound(elements.toArray(), size, 2L));
            Assert.assertEquals(2, JournalObservable.upperBound(elements.toArray(), size, 3L));
            Assert.assertEquals(4, JournalObservable.upperBound(elements.toArray(), size, 4L));
            Assert.assertEquals(4, JournalObservable.upperBound(elements.toArray(), size, 5L));
            Assert.assertEquals(6, JournalObservable.upperBound(elements.toArray(), size, 6L));
            Assert.assertEquals(6, JournalObservable.upperBound(elements.toArray(), size, 7L));
        }
        // even elements
        {
            elements.clear();
            elements.add(ovserver2);
            elements.add(ovserver2);
            elements.add(ovserver4);
            elements.add(ovserver4);
            elements.add(ovserver4);
            elements.add(ovserver6);
            elements.add(ovserver6);
            int size = elements.size();
            Assert.assertEquals(0, JournalObservable.upperBound(elements.toArray(), size, 1L));
            Assert.assertEquals(2, JournalObservable.upperBound(elements.toArray(), size, 2L));
            Assert.assertEquals(2, JournalObservable.upperBound(elements.toArray(), size, 3L));
            Assert.assertEquals(5, JournalObservable.upperBound(elements.toArray(), size, 4L));
            Assert.assertEquals(5, JournalObservable.upperBound(elements.toArray(), size, 5L));
            Assert.assertEquals(7, JournalObservable.upperBound(elements.toArray(), size, 6L));
            Assert.assertEquals(7, JournalObservable.upperBound(elements.toArray(), size, 7L));
        }
        {
            CountDownLatch latch = new CountDownLatch(1);
            System.out.println(latch.getCount());

            latch.countDown();
            System.out.println(latch.getCount());

            latch.countDown();
            System.out.println(latch.getCount());

            latch.countDown();
            System.out.println(latch.getCount());
        }
        System.out.println("success");
    }