h2/src/test/org/h2/test/store/TestConcurrent.java
/**
     * Test the concurrent map implementation.
     */
Test the concurrent map implementation.
Test the concurrent map implementation .
private void testConcurrentMap() throws InterruptedException {
        final MVStore s = openStore(null);
        final MVMap<Integer, Integer> m = s.openMap("data",
                new MVMapConcurrent.Builder<Integer, Integer>());
        final int size = 20;
        final Random rand = new Random(1);
        Task task = new Task() {
            @Override
            public void call() throws Exception {
                try {
                    while (!stop) {
                        if (rand.nextBoolean()) {
                            m.put(rand.nextInt(size), 1);
                        } else {
                            m.remove(rand.nextInt(size));
                        }
                        m.get(rand.nextInt(size));
                        m.firstKey();
                        m.lastKey();
                        m.ceilingKey(5);
                        m.floorKey(5);
                        m.higherKey(5);
                        m.lowerKey(5);
                        for (Iterator<Integer> it = m.keyIterator(null);
                                it.hasNext();) {
                            it.next();
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        task.execute();
        Thread.sleep(1);
        for (int j = 0; j < 100; j++) {
            for (int i = 0; i < 100; i++) {
                if (rand.nextBoolean()) {
                    m.put(rand.nextInt(size), 2);
                } else {
                    m.remove(rand.nextInt(size));
                }
                m.get(rand.nextInt(size));
            }
            s.commit();
            Thread.sleep(1);
        }
        task.get();
        s.close();
    }
private void testConcurrentMap ( ) throws InterruptedException { final MVStore s = openStore ( null ) ; final MVMap < Integer , Integer > m = s . openMap ( "data" , new MVMapConcurrent . Builder < Integer , Integer > ( ) ) ; final int size = 20 ; final Random rand = new Random ( 1 ) ; Task task = new Task ( ) { @ Override public void call ( ) throws Exception { try { while ( ! stop ) { if ( rand . nextBoolean ( ) ) { m . put ( rand . nextInt ( size ) , 1 ) ; } else { m . remove ( rand . nextInt ( size ) ) ; } m . get ( rand . nextInt ( size ) ) ; m . firstKey ( ) ; m . lastKey ( ) ; m . ceilingKey ( 5 ) ; m . floorKey ( 5 ) ; m . higherKey ( 5 ) ; m . lowerKey ( 5 ) ; for ( Iterator < Integer > it = m . keyIterator ( null ) ; it . hasNext ( ) ; ) { it . next ( ) ; } } } catch ( Exception e ) { e . printStackTrace ( ) ; } } } ; task . execute ( ) ; Thread . sleep ( 1 ) ; for ( int j = 0 ; j < 100 ; j ++ ) { for ( int i = 0 ; i < 100 ; i ++ ) { if ( rand . nextBoolean ( ) ) { m . put ( rand . nextInt ( size ) , 2 ) ; } else { m . remove ( rand . nextInt ( size ) ) ; } m . get ( rand . nextInt ( size ) ) ; } s . commit ( ) ; Thread . sleep ( 1 ) ; } task . get ( ) ; s . close ( ) ; }
Test the concurrent map implementation.
Test the concurrent map implementation .