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

📄 teststoragemodifier.java

📁 lucene2.2.0版本
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            ReferenceCounter<StorageQuery> query = this.controller                    .getStorageQuery();            if (i % 2 == 0 || i < 10) {                assertNull(query.get().singleEntryQuery("" + i, feedId,                        this.configurator));            } else                assertEquals("" + i, query.get().singleEntryQuery("" + i,                        feedId, this.configurator).getId());            query.decrementRef();        }        this.controller.forceWrite();        IndexSearcher searcher = new IndexSearcher(this.dir);        for (int i = 1; i < this.count; i++) {            Query luceneQuery = new TermQuery(new Term(                    StorageEntryWrapper.FIELD_ENTRY_ID, "" + i));            Hits hits = searcher.search(luceneQuery);            if (i % 2 == 0 || i < 10) {                assertEquals(0, hits.length());            } else                assertEquals(1, hits.length());        }        searcher.close();    }    public void testSaveUser() throws StorageException, IOException {        GDataAccount user = new GDataAccount();        user.setName(username);        user.setPassword(password);        StorageAccountWrapper wrapper = new StorageAccountWrapper(user);        this.modifier.createAccount(wrapper);        IndexSearcher searcher = new IndexSearcher(this.dir);        Query q = new TermQuery(new Term(StorageAccountWrapper.FIELD_ACCOUNTNAME,                username));        Hits h = searcher.search(q);        assertEquals("length == 1", 1, h.length());        GDataAccount storedUser = StorageAccountWrapper.buildEntity(h.doc(0));        assertTrue(storedUser.equals(user));        searcher.close();    }    public void testDeleteUser() throws StorageException, IOException {        testSaveUser();        this.modifier.deleteAccount(username);        IndexSearcher searcher = new IndexSearcher(this.dir);        Query q = new TermQuery(new Term(StorageAccountWrapper.FIELD_ACCOUNTNAME,                username));        Hits h = searcher.search(q);        assertEquals("length == 0", 0, h.length());        searcher.close();    }    public void testUpdateUser() throws StorageException, IOException {        testSaveUser();        GDataAccount user = new GDataAccount();        user.setName(username);        user.setPassword("newPass");        StorageAccountWrapper wrapper = new StorageAccountWrapper(user);        this.modifier.updateAccount(wrapper);        IndexSearcher searcher = new IndexSearcher(this.dir);        Query q = new TermQuery(new Term(StorageAccountWrapper.FIELD_ACCOUNTNAME,                username));        Hits h = searcher.search(q);        assertEquals("length == 1", 1, h.length());        GDataAccount storedUser = StorageAccountWrapper.buildEntity(h.doc(0));        assertTrue(storedUser.equals(user));        assertFalse(storedUser.getPassword().equals(password));        searcher.close();    }    public void testSaveFeed() throws IOException, StorageException {        String title = "myTitle";        ServerBaseFeed feed = new ServerBaseFeed();        feed.setId(feedId);        feed.setTitle(new PlainTextConstruct(title));        feed.setServiceType(service);        feed.setServiceConfig(this.configurator);        StorageFeedWrapper wrapper = new StorageFeedWrapper(feed,username);        this.modifier.createFeed(wrapper);                IndexSearcher searcher = new IndexSearcher(this.dir);        Query q = new TermQuery(new Term(StorageFeedWrapper.FIELD_FEED_ID,                feedId));        Hits h = searcher.search(q);        assertEquals("length == 1", 1, h.length());        searcher.close();            }    public void testDeleteFeed() throws IOException, StorageException {        testSaveFeed();        Entry e = new Entry();        e.setTitle(new PlainTextConstruct("hello world"));        ServerBaseEntry entry = new ServerBaseEntry(e);        entry.setFeedId(feedId);        entry.setId("testme");        entry.setServiceConfig(this.configurator);        StorageEntryWrapper entryWrapper = new StorageEntryWrapper(entry,StorageOperation.INSERT);        this.modifier.insertEntry(entryWrapper);        this.modifier.forceWrite();        this.modifier.deleteFeed(feedId);        IndexSearcher searcher = new IndexSearcher(this.dir);        Query q = new TermQuery(new Term(StorageFeedWrapper.FIELD_FEED_ID,                feedId));        Query q1 = new TermQuery(new Term(StorageEntryWrapper.FIELD_FEED_REFERENCE,                feedId));        BooleanQuery boolQuery = new BooleanQuery();        boolQuery.add(q,BooleanClause.Occur.SHOULD);        boolQuery.add(q1,BooleanClause.Occur.SHOULD);        Hits h = searcher.search(boolQuery);        assertEquals("length == 0", 0, h.length());        searcher.close();                            }    /**     * @throws IOException     * @throws StorageException     */    public void testUpdateFeed() throws IOException, StorageException {        testSaveFeed();        ServerBaseFeed feed = new ServerBaseFeed();        String title = "myTitle";        String newusername = "doug";        feed.setTitle(new PlainTextConstruct(title));        feed.setId(feedId);        feed.setServiceType(service);        feed.setServiceConfig(this.configurator);        StorageFeedWrapper wrapper = new StorageFeedWrapper(feed,newusername);        this.modifier.updateFeed(wrapper);        IndexSearcher searcher = new IndexSearcher(this.dir);        Query q = new TermQuery(new Term(StorageFeedWrapper.FIELD_FEED_ID,                feedId));        Hits h = searcher.search(q);        assertEquals("length == 1", 1, h.length());        assertTrue(h.doc(0).get(StorageFeedWrapper.FIELD_ACCOUNTREFERENCE).equals(newusername));        searcher.close();    }    private Thread getRunnerThread(int idIndex) {        Thread t = new Thread(new Runner(idIndex));        return t;    }    private class Runner implements Runnable {        private int idIndex;        public Runner(int idIndex) {            this.idIndex = idIndex;        }        public void run() {            for (int i = idIndex; i < idIndex + 10; i++) {                BaseEntry e = buildEntry("" + i);                try {                    ServerBaseEntry en = new ServerBaseEntry(e);                    en.setFeedId(feedId);                    en.setServiceConfig(configurator);                    StorageEntryWrapper wrapper = new StorageEntryWrapper(en,                            StorageOperation.INSERT);                    modifier.insertEntry(wrapper);//                    System.out.println("insert: "+i+" Thread: "+Thread.currentThread().getName());                } catch (Exception e1) {                    e1.printStackTrace();                }            }        }// end run        private BaseEntry buildEntry(String id) {            Entry e = new Entry();            e.setId(id);            e.setTitle(new PlainTextConstruct("Monty Python"));            e.setPublished(DateTime.now());            e.setUpdated(DateTime.now());            String content = "1st soldier with a keen interest in birds: Who goes there?"                    + "King Arthur: It is I, Arthur, son of Uther Pendragon, from the castle of Camelot. King of the Britons, defeater of the Saxons, Sovereign of all England!"                    + "1st soldier with a keen interest in birds: Pull the other one!"                    + "King Arthur: I am, and this is my trusty servant Patsy. We have ridden the length and breadth of the land in search of knights who will join me in my court at Camelot. I must speak with your lord and master."                    + "1st soldier with a keen interest in birds: What? Ridden on a horse?"                    + "King Arthur: Yes!";            e.setContent(new TextContent(new PlainTextConstruct(content)));            e.setSummary(new PlainTextConstruct("The Holy Grail"));            return e;        }    }        private ServerBaseEntry getServerEntry(BaseEntry e){        ServerBaseEntry en = new ServerBaseEntry(e);        en.setFeedId(feedId);        en.setServiceConfig(this.configurator);        return en;    }}

⌨️ 快捷键说明

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