TestStorageQuerypublic class TestStorageQuery extends TestCase 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. |
Fields Summary |
---|
private StorageModifier | modifier | private int | count | private org.apache.lucene.gdata.utils.ReferenceCounter | query | private org.apache.lucene.gdata.server.registry.ProvidedService | configurator | private StorageCoreController | controller | private Directory | dir | private static String | feedId | private static String | accountName | private static String | service |
Methods Summary |
---|
private void | entryQueryHelper(org.apache.lucene.gdata.utils.ReferenceCounter currentQuery)
List<String> entryIdList = new ArrayList<String>();
for (int i = 1; i <= this.count; i++) {
entryIdList.add(""+i);
}
List<BaseEntry> entryList = currentQuery.get().entryQuery(entryIdList,feedId,this.configurator);
assertEquals(entryIdList.size(),entryList.size());
List<String> entryIdCompare = new ArrayList<String>();
for (BaseEntry entry : entryList) {
assertEquals("1",entry.getVersionId());
entryIdCompare.add(entry.getId());
}
assertTrue(entryIdList.containsAll(entryIdCompare));
| private void | feedQueryHelper(org.apache.lucene.gdata.utils.ReferenceCounter currentQuery)
BaseFeed feed = currentQuery.get().getLatestFeedQuery(feedId,25,1,this.configurator);
List<BaseEntry> entryList = feed.getEntries();
assertTrue("listSize: "+entryList.size(),entryList.size() == 25);
BaseEntry tempEntry = null;
for (BaseEntry entry : entryList) {
assertNotNull("entry",entry);
if(tempEntry != null){
assertTrue(tempEntry.getUpdated().compareTo(entry.getUpdated())>=0) ;
tempEntry = entry;
}else
tempEntry = entry;
}
// test sub retrieve sublist
int offset = 15;
int resultCount = 5;
feed = currentQuery.get().getLatestFeedQuery(feedId,resultCount,offset,this.configurator);
List<BaseEntry> entrySubList = feed.getEntries();
assertTrue("listSize: "+entrySubList.size(),entrySubList.size() == resultCount);
offset--;
for (BaseEntry entry : entrySubList) {
assertEquals(entry.getId(),entryList.get(offset).getId());
offset++;
}
| public void | insertEntries(int entrycount)
List<StorageEntryWrapper> tempList = new ArrayList<StorageEntryWrapper>();
for (int i = 0; i <= entrycount ; i++) {
ServerBaseEntry entry = new ServerBaseEntry(new Entry());
entry.setId(""+i);
entry.setServiceConfig(this.configurator);
entry.setUpdated(new DateTime(System.currentTimeMillis(),0));
entry.setFeedId(feedId);
StorageEntryWrapper wrapper = new StorageEntryWrapper(entry,StorageOperation.INSERT);
tempList.add(i,wrapper);
// force different timestamps --> DateTime 2006-06-05T13:37:55.724Z
Thread.sleep(10);
}
for (StorageEntryWrapper entry : tempList) {
this.modifier.insertEntry(entry);
}
| protected void | setUp()
this.configurator = new ProvidedServiceStub();
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();
ServerBaseFeed feed = new ServerBaseFeed();
feed.setId(feedId);
feed.setServiceType(service);
feed.setServiceConfig(this.configurator);
StorageFeedWrapper wrapper = new StorageFeedWrapper(feed,accountName);
this.modifier.createFeed(wrapper);
insertEntries(this.count);
this.query = this.controller.getStorageQuery();
| protected void | tearDown()
this.query.decrementRef();
this.controller.destroy();
| public void | testAccountNameQuery()
ReferenceCounter<StorageQuery> query = this.controller.getStorageQuery();
assertEquals(accountName,query.get().getAccountNameForFeedId(feedId));
assertNull(query.get().getAccountNameForFeedId("someId"));
| public void | testCheckVersionId()
this.modifier.forceWrite();
ReferenceCounter<StorageQuery> sQuery = this.controller.getStorageQuery();
ServerBaseEntry entry = new ServerBaseEntry(new Entry());
entry.setId("test");
entry.setServiceConfig(this.configurator);
entry.setUpdated(new DateTime(System.currentTimeMillis(),0));
entry.setFeedId(feedId);
entry.setVersion(5);
StorageEntryWrapper wrapper = new StorageEntryWrapper(entry,StorageOperation.INSERT);
this.modifier.insertEntry(wrapper);
//test in buffer
assertTrue(sQuery.get().checkEntryVersion(entry.getId(),entry.getFeedId(),entry.getVersion()));
assertFalse(sQuery.get().checkEntryVersion(entry.getId(),entry.getFeedId(),10000));
assertFalse(sQuery.get().checkEntryVersion(entry.getId(),"someOtherFeed",entry.getVersion()));
assertFalse(sQuery.get().checkEntryVersion("foobar",entry.getFeedId(),entry.getVersion()));
this.modifier.forceWrite();
//test in buffer after written
assertTrue(sQuery.get().checkEntryVersion(entry.getId(),entry.getFeedId(),entry.getVersion()));
assertFalse(sQuery.get().checkEntryVersion(entry.getId(),entry.getFeedId(),10000));
assertFalse(sQuery.get().checkEntryVersion(entry.getId(),"someOtherFeed",entry.getVersion()));
assertFalse(sQuery.get().checkEntryVersion("foobar",entry.getFeedId(),entry.getVersion()));
sQuery.decrementRef();
sQuery = this.controller.getStorageQuery();
//test in index
assertTrue(sQuery.get().checkEntryVersion(entry.getId(),entry.getFeedId(),entry.getVersion()));
assertFalse(sQuery.get().checkEntryVersion(entry.getId(),entry.getFeedId(),10000));
assertFalse(sQuery.get().checkEntryVersion("foobar",entry.getFeedId(),entry.getVersion()));
sQuery.decrementRef();
| public void | testEntryQuery()
entryQueryHelper(this.query);
this.controller.forceWrite();
ReferenceCounter<StorageQuery> queryAssureWritten = this.controller.getStorageQuery();
assertNotSame(queryAssureWritten,query);
entryQueryHelper(queryAssureWritten);
queryAssureWritten.decrementRef();
| public void | testFeedQuery()
feedQueryHelper(this.query);
this.controller.forceWrite();
ReferenceCounter<StorageQuery> queryAssureWritten = this.controller.getStorageQuery();
assertNotSame(queryAssureWritten,this.query);
feedQueryHelper(queryAssureWritten);
queryAssureWritten.decrementRef();
| public void | testGetEntryLastModied()
ServerBaseEntry entry = new ServerBaseEntry(new Entry());
entry.setId("test");
entry.setServiceConfig(this.configurator);
entry.setUpdated(new DateTime(System.currentTimeMillis(),0));
entry.setFeedId(feedId);
StorageEntryWrapper wrapper = new StorageEntryWrapper(entry,StorageOperation.INSERT);
this.modifier.insertEntry(wrapper);
assertEquals(entry.getUpdated().getValue(),this.query.get().getEntryLastModified("test",feedId));
this.modifier.forceWrite();
assertEquals(entry.getUpdated().getValue(),this.query.get().getEntryLastModified("test",feedId));
this.query = this.controller.getStorageQuery();
assertEquals(entry.getUpdated().getValue(),this.query.get().getEntryLastModified("test",feedId));
try{
this.query.get().getEntryLastModified("some",feedId);
fail("exception expected");
}catch (Exception e) {
e.printStackTrace();
}
| public void | testGetFeedLastModified()
ServerBaseEntry entry = new ServerBaseEntry(new Entry());
entry.setId("test");
entry.setServiceConfig(this.configurator);
entry.setUpdated(new DateTime(System.currentTimeMillis(),0));
entry.setFeedId(feedId);
StorageEntryWrapper wrapper = new StorageEntryWrapper(entry,StorageOperation.INSERT);
this.modifier.insertEntry(wrapper);
assertEquals(entry.getUpdated().getValue(),this.query.get().getFeedLastModified(feedId));
this.modifier.forceWrite();
assertEquals(entry.getUpdated().getValue(),this.query.get().getFeedLastModified(feedId));
this.query = this.controller.getStorageQuery();
assertEquals(entry.getUpdated().getValue(),this.query.get().getFeedLastModified(feedId));
| public void | testGetUser()
this.modifier.forceWrite();
GDataAccount user = new GDataAccount();
user.setName("simon");
user.setPassword("pass");
user.setAuthorname("simon willnauer");
user.setAuthorMail("simon@apache.org");
user.setAuthorLink(new URL("http://www.apache.org"));
this.modifier.createAccount(new StorageAccountWrapper(user));
GDataAccount queriedUser = this.query.get().getUser("simon");
assertNull(queriedUser);
ReferenceCounter<StorageQuery> tempQuery = this.controller.getStorageQuery();
queriedUser = tempQuery.get().getUser("simon");
assertTrue(queriedUser.equals(user));
assertTrue(queriedUser.getAuthorMail().equals(user.getAuthorMail()));
assertTrue(queriedUser.getAuthorLink().equals(user.getAuthorLink()));
assertTrue(queriedUser.getAuthorname().equals(user.getAuthorname()));
assertTrue(queriedUser.getPassword().equals(user.getPassword()));
| public void | testIsEntryStored()
assertTrue(this.query.get().isEntryStored(""+(this.count-1),feedId));
assertFalse(this.query.get().isEntryStored("someOther",feedId));
this.modifier.forceWrite();
assertTrue(this.query.get().isEntryStored(""+(this.count-1),feedId));
this.query = this.controller.getStorageQuery();
assertTrue(this.query.get().isEntryStored(""+(this.count-1),feedId));
assertFalse(this.query.get().isEntryStored("someOther",feedId));
| public void | testSingleEntryQuery()
for (int i = 1; i <= this.count; i++) {
BaseEntry entry = this.query.get().singleEntryQuery(""+i,feedId,this.configurator);
assertEquals(""+i,entry.getId());
}
|
|