Package com.taobao.metamorphosis.utils.test

Examples of com.taobao.metamorphosis.utils.test.ConcurrentTestCase


    @Test
    public void testConcurrentAppendMessages() throws Exception {
        System.out.println("Begin concurrent test....");
        this.metaConfig.setMaxSegmentSize(1024 * 1024 * 16);
        ConcurrentTestCase testCase = new ConcurrentTestCase(80, 1000, new ConcurrentTestTask() {

            @Override
            public void run(int index, int times) throws Exception {
                final PutCommand cmd =
                        new PutCommand(MessageStoreUnitTest.this.topic, MessageStoreUnitTest.this.partition,
                            new byte[1024], null, 0, 0);
                final long id = MessageStoreUnitTest.this.idWorker.nextId();
                final CountDownLatch latch = new CountDownLatch(1);
                MessageStoreUnitTest.this.messageStore.append(id, cmd, new AppendCallback() {
                    @Override
                    public void appendComplete(final Location location) {
                        if (location.getOffset() < 0) {
                            throw new RuntimeException();
                        }
                        else {
                            latch.countDown();
                        }
                    }

                });
                try {
                    latch.await();
                }
                catch (InterruptedException e) {
                    // ignore
                }
            }
        });
        testCase.start();
        System.out.println("Appended 80000 messages,cost:" + testCase.getDurationInMillis() / 1000 + " seconds");
        assertEquals(80000, this.messageStore.getMessageCount());

    }
View Full Code Here


    }


    private static long testSystem() {
        final AtomicLong result = new AtomicLong(0);
        final ConcurrentTestCase testCase = new ConcurrentTestCase(50, 400000, new ConcurrentTestTask() {

            public void run(final int index, final int times) throws Exception {
                result.addAndGet(System.currentTimeMillis());

            }
        });
        testCase.start();
        System.out.println("System:" + result.get());
        return testCase.getDurationInMillis();
    }
View Full Code Here

    }


    private static long testSystemTimer() {
        final AtomicLong result = new AtomicLong(0);
        final ConcurrentTestCase testCase = new ConcurrentTestCase(50, 400000, new ConcurrentTestTask() {

            public void run(final int index, final int times) throws Exception {
                result.addAndGet(SystemTimer.currentTimeMillis());

            }
        });
        testCase.start();
        System.out.println("SystemTimer:" + result.get());
        return testCase.getDurationInMillis();
    }
View Full Code Here

    @Test
    public void concurrentTest() throws Exception {
        final Random rand = new Random();
        final AtomicInteger gen = new AtomicInteger();
        final ConcurrentTestCase testCase = new ConcurrentTestCase(100, 1000, new ConcurrentTestTask() {

            @Override
            public void run(final int index, final int times) throws Exception {
                final int id = gen.incrementAndGet();
                final LocalTransactionId xid = new LocalTransactionId("test", id);
                for (int j = 0; j < rand.nextInt(3) + 1; j++) {
                    final int partition = rand.nextInt(10);
                    final MessageStore store =
                            JournalTransactionStoreUnitTest.this.messageStoreManager.getOrCreateMessageStore("topic1",
                                partition % 10);
                    JournalTransactionStoreUnitTest.this.transactionStore.addMessage(store, 1, new PutCommand("topic1",
                        partition, ("msg" + id).getBytes(), xid, 0, 1), null);
                }
                if (id % 100 == 0) {
                    JournalTransactionStoreUnitTest.this.journalStore.checkpoint();
                }
                // commit
                JournalTransactionStoreUnitTest.this.transactionStore.commit(xid, false);

            }
        });

        testCase.start();

        System.out.println("����ʱ�䣺" + testCase.getDurationInMillis() + "ms");

        for (int i = 0; i < 10; i++) {
            final MessageStore store = this.messageStoreManager.getOrCreateMessageStore("topic1", i);
            assertTrue(store.getSizeInBytes() > 0);
        }
View Full Code Here


    @Test
    public void concurrentTest() {
        final AtomicLong counter = new AtomicLong(0);
        ConcurrentTestCase testCase = new ConcurrentTestCase(100, 100000, new ConcurrentTestTask() {

            @Override
            public void run(int index, int times) throws Exception {
                long v = counter.incrementAndGet();
                ConcurrentLRUHashMapUnitTest.this.map.put(String.valueOf(v), (byte) 1);

            }
        });
        testCase.start();
        System.out.println(testCase.getDurationInMillis());
        assertEquals(100, this.map.size());
    }
View Full Code Here

                }
            }

        }.start();

        final ConcurrentTestCase testCase = new ConcurrentTestCase(500, 10000, new ConcurrentTestTask() {

            @Override
            public void run(final int index, final int times) throws Exception {
                FetchRequestQueueUnitTest.this.fetchRequestQueue.offer(new FetchRequest(times % 3));
                try {
                    FetchRequestQueueUnitTest.this.fetchRequestQueue.take();
                    counter.incrementAndGet();
                }
                catch (final InterruptedException e) {

                }
            }
        });
        testCase.start();
        assertEquals(5000000, counter.get());
        assertEquals(0, this.fetchRequestQueue.size());
        System.out.println(testCase.getDurationInMillis());
        shutdown.set(true);
    }
View Full Code Here


    @Test
    public void concurrentTest() {
        final AtomicLong ids = new AtomicLong();
        final ConcurrentTestCase testCase = new ConcurrentTestCase(100, 10000, new ConcurrentTestTask() {

            @Override
            public void run(final int index, final int times) throws Exception {
                final long id = IdWorkerUnitTest.this.idWorker1.nextId();
                if (id < 0) {
                    throw new RuntimeException("error");
                }
                ids.addAndGet(id);
            }
        });
        testCase.start();
        System.out.println(ids.get());
        System.out.println(testCase.getDurationInMillis());
    }
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.utils.test.ConcurrentTestCase

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.