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

📄 teststoragemodifier.java

📁 lucene2.2.0版本
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**  * Copyright 2004 The Apache Software Foundation  *  * Licensed under the Apache License, Version 2.0 (the "License");  * you may not use this file except in compliance with the License.  * You may obtain a copy of the License at  *  *     http://www.apache.org/licenses/LICENSE-2.0  *  * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.  */package org.apache.lucene.gdata.storage.lucenestorage;import java.io.IOException;import junit.framework.TestCase;import org.apache.lucene.gdata.data.GDataAccount;import org.apache.lucene.gdata.data.ServerBaseEntry;import org.apache.lucene.gdata.data.ServerBaseFeed;import org.apache.lucene.gdata.server.registry.ProvidedService;import org.apache.lucene.gdata.storage.StorageException;import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper.StorageOperation;import org.apache.lucene.gdata.utils.ProvidedServiceStub;import org.apache.lucene.gdata.utils.ReferenceCounter;import org.apache.lucene.index.Term;import org.apache.lucene.search.BooleanClause;import org.apache.lucene.search.BooleanQuery;import org.apache.lucene.search.Hits;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.Query;import org.apache.lucene.search.TermQuery;import org.apache.lucene.store.Directory;import org.apache.lucene.store.RAMDirectory;import com.google.gdata.data.BaseEntry;import com.google.gdata.data.DateTime;import com.google.gdata.data.Entry;import com.google.gdata.data.PlainTextConstruct;import com.google.gdata.data.TextContent;import com.google.gdata.util.ParseException;public class TestStorageModifier extends TestCase {    private StorageModifier modifier;    private int count = 1;    private ProvidedService configurator;    private Directory dir;    private StorageCoreController controller;    private static String feedId = "myFeed";    private static String username = "simon";    private static String password = "test";    private static String service = "myService";    protected void setUp() throws Exception {        this.controller = new StorageCoreController();        this.dir = new RAMDirectory();        this.controller.setStorageDir(this.dir);        this.controller.setKeepRecoveredFiles(false);        this.controller.setOptimizeInterval(10);        this.controller.setRecover(false);        this.controller.setBufferSize(10);        this.controller.setPersistFactor(10);        this.controller.initialize();        this.configurator = new ProvidedServiceStub();        this.modifier = this.controller.getStorageModifier();        this.dir = this.controller.getDirectory();    }    protected void tearDown() throws Exception {        this.count = 1;        // destroy all resources        this.controller.destroy();            }    /*     * Test method for     * 'org.apache.lucene.storage.lucenestorage.StorageModifier.updateEntry(StroageEntryWrapper)'     */    public void testUpdateEntry() throws IOException, InterruptedException,            ParseException, StorageException {        testInsertEntry();        for (int i = 1; i < this.count; i++) {            Entry e = new Entry();            e.setId("" + i);            String insertString = "Hello world" + i;            e.setTitle(new PlainTextConstruct(insertString));            ServerBaseEntry en = getServerEntry(e);            StorageEntryWrapper wrapper = new StorageEntryWrapper(en,                    StorageOperation.UPDATE);            this.modifier.updateEntry(wrapper);            ReferenceCounter<StorageQuery> innerQuery = this.controller                    .getStorageQuery();            BaseEntry fetchedEntry = innerQuery.get().singleEntryQuery("" + i,                    feedId, this.configurator);            assertEquals("updated Title:", insertString, fetchedEntry                    .getTitle().getPlainText());        }        // double updates        for (int i = 1; i < this.count; i++) {            Entry e = new Entry();            e.setId("" + i);            String insertString = "Hello world" + i;            e.setTitle(new PlainTextConstruct(insertString));            ServerBaseEntry en = getServerEntry(e);            StorageEntryWrapper wrapper = new StorageEntryWrapper(en,                    StorageOperation.UPDATE);            this.modifier.updateEntry(wrapper);            e = new Entry();            e.setId("" + i);            insertString = "Foo Bar" + i;            e.setTitle(new PlainTextConstruct(insertString));            en = getServerEntry(e);            wrapper = new StorageEntryWrapper(en,                    StorageOperation.UPDATE);            this.modifier.updateEntry(wrapper);            ReferenceCounter<StorageQuery> innerQuery = this.controller                    .getStorageQuery();            BaseEntry fetchedEntry = innerQuery.get().singleEntryQuery("" + i,                    feedId, this.configurator);            assertEquals("updated Title:", insertString, fetchedEntry                    .getTitle().getPlainText());        }                   }    /*     * Test method for     * 'org.apache.lucene.storage.lucenestorage.StorageModifier.insertEntry(StroageEntryWrapper)'     */    public void testInsertEntry() throws IOException, InterruptedException,            ParseException, StorageException {        Thread a = getRunnerThread(this.count);                Thread b = getRunnerThread((this.count += 10));        b.start();        a.start();//         wait for the first thread to check for the inserted entries        a.join();          try{        for (int i = 1; i < this.count; i++) {                       ReferenceCounter<StorageQuery> innerQuery = this.controller                    .getStorageQuery();            BaseEntry e = innerQuery.get().singleEntryQuery("" + i, feedId,                    this.configurator);            assertNotNull(e);            assertEquals("get entry for id" + i, "" + i, e.getId());        }        }finally{        	/*        	 * if an exception occures the tread can at least finnish running before the        	 * controller will be closed in the tearDown method        	 */        	 b.join();	        }                     ReferenceCounter<StorageQuery> query = this.controller                .getStorageQuery();        this.count += 10;        for (int i = 1; i < this.count; i++) {            BaseEntry e = query.get().singleEntryQuery("" + i, feedId,                    this.configurator);            assertEquals("get entry for id" + i, "" + i, e.getId());        }        BaseEntry e = query.get().singleEntryQuery("" + this.count, feedId,                this.configurator);        assertNull("not entry for ID", e);        query.decrementRef();    }    /*     * Test method for     * 'org.apache.lucene.storage.lucenestorage.StorageModifier.deleteEntry(String)'     */    public void testDeleteEntry() throws IOException, InterruptedException,            ParseException, StorageException {        testInsertEntry();        for (int i = 1; i < this.count; i++) {            if (i % 2 == 0 || i < 10) {                ServerBaseEntry entry = new ServerBaseEntry();                entry.setId("" + i);                entry.setFeedId(feedId);                this.modifier.deleteEntry(new StorageEntryWrapper(entry,StorageOperation.DELETE));            }

⌨️ 快捷键说明

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