⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 namedobjectstoreperftest.java

📁 利用SyncML开发客户端程序的中间件
💻 JAVA
字号:
/*
 * Copyright (C) 2003-2007 Funambol
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */

package com.funambol.storage;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import jmunit.framework.cldc10.AssertionFailedException;
import jmunit.framework.cldc10.TestCase;
import jmunit.framework.cldc10.TestSuite;

import com.funambol.util.Log;

/**
 * Test case for the NamedObjectStore class
 */
public class NamedObjectStorePerfTest extends TestCase {

    private NamedObjectStore os = null;
    private static final String STORENAME = "PerfTest";
    private static final int OBJNUMBER = 300;

    public NamedObjectStorePerfTest() {
        super(3, "NamedObjectStorePerfTest");
        Log.setLogLevel(Log.INFO);
    }
    
    /**
     * Set up the tests
     */
    public void setUp() {

        os = new NamedObjectStore();
        try {
            os.open(STORENAME);
            os.close();
        }
        catch (Exception ex) {
            Log.info(STORENAME + " not found, creating it....");
            try {
                os.create(STORENAME);

                for (int i=1; i<=OBJNUMBER; i++) {
                    TestClass tc = new TestClass("TestClass_"+i);
                    os.store("Test"+i, tc);
                }
                os.close();
            }
            catch(Exception e){
                e.printStackTrace();
                return;
            }
        }
        Log.setLogLevel(Log.ERROR);
    }

    /**
     * Clean up resources
     */
    public void tearDown() {
    }

    /**
     * Run the tests
     */
    public void test(int testNumber) throws Throwable {
        
        switch(testNumber) {
           case 0: testRetrieveOne("Test100");     break;
           case 1: testRetrieveOne("Test50");      break;
           case 2: testRetrieveAll();              break;
           default:                                break;
        }
    }

    /**
     * Test #1: Test to retrieve the a large number of objects.
     */
    private void testRetrieveOne(String name) throws Exception {
        os.open(STORENAME);
        TestClass tc = new TestClass();
        os.retrieve(name, tc);
        Log.info(tc.toString());
    }

    /**
     * Test #1: Test to retrieve the a large number of objects.
     */
    private void testRetrieveAll() throws Exception {
        os.open(STORENAME);
        TestClass tc = new TestClass();
        for (int i=1; i<=OBJNUMBER; i++) {
            os.retrieve("Test"+i, tc);
            Log.info(tc.toString());

        }
        os.close();
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -