You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by yo...@apache.org on 2006/07/26 00:23:06 UTC
svn commit: r425538 [3/4] - in /lucene/java/trunk: ./ contrib/gdata-server/
contrib/gdata-server/src/java/org/apache/lucene/gdata/data/
contrib/gdata-server/src/java/org/apache/lucene/gdata/server/
contrib/gdata-server/src/java/org/apache/lucene/gdata/...
Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageQuery.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageQuery.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageQuery.java Tue Jul 25 15:23:01 2006
@@ -17,6 +17,7 @@
package org.apache.lucene.gdata.storage.lucenestorage;
import java.io.IOException;
+import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Iterator;
@@ -25,6 +26,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
import org.apache.lucene.gdata.data.GDataAccount;
import org.apache.lucene.gdata.server.GDataEntityBuilder;
import org.apache.lucene.gdata.server.registry.ProvidedService;
@@ -66,6 +68,7 @@
*/
public class StorageQuery {
private static final Log LOG = LogFactory.getLog(StorageQuery.class);
+
private final StorageBuffer buffer;
private final Searcher searcher;
@@ -178,20 +181,19 @@
@SuppressWarnings("unchecked")
public BaseFeed getLatestFeedQuery(final String feedId,
final int resultCount, final int startIndex,
- final ProvidedService config) throws IOException,
- ParseException {
+ final ProvidedService config) throws IOException, ParseException {
DateTime updated = null;
Hits feedHits = storageFeedQuery(feedId);
- if(feedHits.length() == 0)
+ if (feedHits.length() == 0)
return null;
- BaseFeed retVal = buildFeedFromLuceneDocument(feedHits.doc(0),config);
-
+ BaseFeed retVal = buildFeedFromLuceneDocument(feedHits.doc(0), config);
+
List<BaseEntry> returnList = new ArrayList<BaseEntry>(resultCount);
List<StorageEntryWrapper> bufferedWrapperList = this.buffer
.getSortedEntries(feedId);
int alreadyAdded = 0;
int offset = startIndex - 1;
-
+
if (bufferedWrapperList != null
&& bufferedWrapperList.size() >= startIndex) {
updated = bufferedWrapperList.get(0).getEntry().getUpdated();
@@ -199,14 +201,13 @@
if ((bufferedWrapperList.size() - offset) > 0) {
StorageEntryWrapper wrappedEntry = bufferedWrapperList
.get(offset++);
- returnList
- .add(wrappedEntry.getEntry());
+ returnList.add(wrappedEntry.getEntry());
} else
break;
}
// reset offset
offset = startIndex - 1;
- if (alreadyAdded == resultCount){
+ if (alreadyAdded == resultCount) {
retVal.getEntries().addAll(returnList);
retVal.setUpdated(updated);
return retVal;
@@ -229,14 +230,17 @@
BaseEntry entry = buildEntryFromLuceneDocument(doc, config);
returnList.add(entry);
}
- if(updated == null){
- try{
- long updatedTimeStamp = Long.parseLong(hits.doc(0).get(StorageEntryWrapper.FIELD_TIMESTAMP));
- updated = new DateTime(updatedTimeStamp);
- }catch (Exception e) {
- LOG.warn("could not create DateTime -- "+e.getMessage(),e);
- updated = buildEntryFromLuceneDocument(hits.doc(0),config).getUpdated();
- }
+ if (updated == null) {
+ try {
+ long updatedTimeStamp = Long.parseLong(hits.doc(0).get(
+ StorageEntryWrapper.FIELD_TIMESTAMP));
+ updated = new DateTime(updatedTimeStamp);
+ } catch (Exception e) {
+ LOG.warn("could not create DateTime -- " + e.getMessage(),
+ e);
+ updated = buildEntryFromLuceneDocument(hits.doc(0), config)
+ .getUpdated();
+ }
}
}
retVal.setUpdated(updated);
@@ -351,21 +355,18 @@
}
private BaseEntry buildEntryFromLuceneDocument(final Document doc,
- final ProvidedService config) throws ParseException,
- IOException {
- StringReader reader = new StringReader(doc.getField(
- StorageEntryWrapper.FIELD_CONTENT).stringValue());
- return GDataEntityBuilder.buildEntry( reader, config);
+ final ProvidedService config) throws ParseException, IOException {
+ Reader reader = new StringReader(doc.getField(StorageEntryWrapper.FIELD_CONTENT).stringValue());
+ BaseEntry entry = GDataEntityBuilder.buildEntry(reader, config);
+ entry.setVersionId(doc.getField(StorageEntryWrapper.FIELD_VERSION).stringValue());
+ return entry;
}
private BaseFeed buildFeedFromLuceneDocument(final Document doc,
- final ProvidedService config) throws ParseException,
- IOException {
- StringReader reader = new StringReader(doc.getField(
- StorageFeedWrapper.FIELD_CONTENT).stringValue());
- return GDataEntityBuilder
- .buildFeed(reader, config);
+ final ProvidedService config) throws ParseException, IOException {
+ Reader reader = new StringReader(doc.getField(StorageFeedWrapper.FIELD_CONTENT).stringValue());
+ return GDataEntityBuilder.buildFeed(reader, config);
}
@@ -403,21 +404,28 @@
/**
* Checks whether a feed for the given feedID is stored
- * @param feedId - the feed ID
- * @return <code>true</code> if and only if a feed is stored for the provided feed ID, <code>false</code> if no feed for the given id is stored
+ *
+ * @param feedId -
+ * the feed ID
+ * @return <code>true</code> if and only if a feed is stored for the
+ * provided feed ID, <code>false</code> if no feed for the given
+ * id is stored
* @throws IOException
*/
- public boolean isFeedStored(String feedId)throws IOException{
+ public boolean isFeedStored(String feedId) throws IOException {
Hits h = storageFeedQuery(feedId);
return (h.length() > 0);
-
+
}
/**
* Looks up the feedtype for the given feed ID
- * @param feedID - the feed ID
+ *
+ * @param feedID -
+ * the feed ID
* @return - the feed type
- * @throws IOException - if the storage can not be accessed
+ * @throws IOException -
+ * if the storage can not be accessed
*/
public String getService(String feedID) throws IOException {
Hits hits = storageFeedQuery(feedID);
@@ -427,6 +435,7 @@
String feedType = doc.get(StorageFeedWrapper.FIELD_SERVICE_ID);
return feedType;
}
+
private Hits storageFeedQuery(String feedId) throws IOException {
TermQuery query = new TermQuery(new Term(
StorageFeedWrapper.FIELD_FEED_ID, feedId));
@@ -435,58 +444,103 @@
/**
* Looks up the account reference for the given feed id
- * @param feedId - id of the feed
- * @return - the name of the account associated with the feed for the given feed id, or <code>null</code> if the feed is not stored
- * @throws IOException - if the storage can not be accessed
+ *
+ * @param feedId -
+ * id of the feed
+ * @return - the name of the account associated with the feed for the given
+ * feed id, or <code>null</code> if the feed is not stored
+ * @throws IOException -
+ * if the storage can not be accessed
*/
public String getAccountNameForFeedId(String feedId) throws IOException {
Hits h = storageFeedQuery(feedId);
- if(h.length() == 0)
+ if (h.length() == 0)
return null;
Document doc = h.doc(0);
return doc.get(StorageFeedWrapper.FIELD_ACCOUNTREFERENCE);
-
+
}
- protected long getEntryLastModified(final String entryId,final String feedId) throws IOException, StorageException{
- StorageEntryWrapper wrapper = this.buffer.getEntry(entryId,feedId);
- if(wrapper != null)
+
+ protected long getEntryLastModified(final String entryId,
+ final String feedId) throws IOException, StorageException {
+ StorageEntryWrapper wrapper = this.buffer.getEntry(entryId, feedId);
+ if (wrapper != null)
return wrapper.getTimestamp();
-
+
Hits h = storageQuery(entryId);
- if(h.length() > 0)
- try{
- return Long.parseLong(h.doc(0).get(StorageEntryWrapper.FIELD_TIMESTAMP));
- }catch (Exception e) {
- LOG.warn("Can not parse timestamp from entry -- "+h.doc(0).get(StorageEntryWrapper.FIELD_TIMESTAMP));
+ if (h.length() > 0)
+ try {
+ return Long.parseLong(h.doc(0).get(
+ StorageEntryWrapper.FIELD_TIMESTAMP));
+ } catch (Exception e) {
+ LOG.warn("Can not parse timestamp from entry -- "
+ + h.doc(0).get(StorageEntryWrapper.FIELD_TIMESTAMP));
}
- else
+ else
throw new StorageException("Entry not found");
return 0;
-
+
}
-
- protected long getFeedLastModified(final String feedId)throws IOException{
+
+ protected long getFeedLastModified(final String feedId) throws IOException {
Long bufferedTime = this.buffer.getFeedLastModified(feedId);
- if(bufferedTime != null)
+ if (bufferedTime != null)
return bufferedTime;
- Hits entryHits = storageFeedQuery(feedId,this.timeStampSort);
- if(entryHits.length() > 0){
- try{
- return Long.parseLong(entryHits.doc(0).getField(StorageEntryWrapper.FIELD_TIMESTAMP).stringValue());
- }catch (Exception e) {
- LOG.warn("Can not parse timestamp from entry -- "+entryHits.doc(0).get(StorageEntryWrapper.FIELD_TIMESTAMP));
+ Hits entryHits = storageFeedQuery(feedId, this.timeStampSort);
+ if (entryHits.length() > 0) {
+ try {
+ return Long.parseLong(entryHits.doc(0).getField(
+ StorageEntryWrapper.FIELD_TIMESTAMP).stringValue());
+ } catch (Exception e) {
+ LOG.warn("Can not parse timestamp from entry -- "
+ + entryHits.doc(0).get(
+ StorageEntryWrapper.FIELD_TIMESTAMP));
}
}
return 0;
-
+
}
- protected boolean isEntryStored(String entryId,String feedId) throws IOException{
- if(this.buffer.getEntry(entryId,feedId)!=null)
- return true;
-
+
+ protected boolean isEntryStored(String entryId, String feedId)
+ throws IOException {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Checking isEntryStored for entryid " + entryId
+ + " feedid: " + feedId);
+ if (this.buffer.getEntry(entryId, feedId) != null)
+ return true;
+
Hits h = storageQuery(entryId);
- if(h.length() > 0)
+ if (h.length() > 0)
return true;
+ return false;
+ }
+
+ protected boolean checkEntryVersion(String id, String feedId, int version)
+ throws IOException {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Checking entry version for entryid " + id + " feedid: "
+ + feedId + " version: " + version);
+ StorageEntryWrapper wrapper = this.buffer.getEntry(id, feedId);
+
+ if (wrapper != null)
+ return wrapper.getVersion() == version;
+
+ Hits h = storageQuery(id);
+ if (h.length() < 1)
+ return false;
+ Document doc = h.doc(0);
+ String fieldValue = null;
+ try {
+ fieldValue = doc.getField(StorageEntryWrapper.FIELD_VERSION)
+ .stringValue();
+ int storedVersion = Integer.parseInt(fieldValue);
+ if(LOG.isDebugEnabled())
+ LOG.debug("StoredEntry has version "+storedVersion +" return compare result");
+ return storedVersion == version;
+ } catch (Exception e) {
+ LOG.error("Entry has no parable Version id or field is not set -- "
+ + fieldValue);
+ }
return false;
}
}
Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverController.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverController.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverController.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverController.java Tue Jul 25 15:23:01 2006
@@ -60,18 +60,29 @@
private final boolean recover;
private final boolean keepRecoverFiles;
+ /**
+ * @param recoverDirectory
+ * @param recover
+ * @param keepRecoverFiles
+ */
public RecoverController(final File recoverDirectory, boolean recover, boolean keepRecoverFiles) {
if (recoverDirectory == null)
throw new IllegalArgumentException("directory must not be null");
+ if(!recoverDirectory.exists())
+ recoverDirectory.mkdirs();
if (!recoverDirectory.isDirectory())
- throw new IllegalStateException("the given File is not a directory");
+ throw new IllegalStateException("the given File is not a directory -- "+recoverDirectory);
this.recover = recover;
this.keepRecoverFiles = keepRecoverFiles;
this.recoverDirectory = recoverDirectory;
}
- public void storageModified(StorageEntryWrapper wrapper)
+ /**
+ * @param wrapper
+ * @throws RecoverException
+ */
+public void storageModified(StorageEntryWrapper wrapper)
throws RecoverException {
// prevent deadlock either recovering or writing
if(this.recover){
@@ -92,6 +103,9 @@
}
}
+ /**
+ * @param modifier
+ */
public void recoverEntries(final StorageModifier modifier){
// prevent deadlock either recovering or writing
if(!this.recover){
@@ -105,14 +119,17 @@
for (int i = 0; i < files.length; i++) {
if(!files[i].isDirectory()){
try{
+ LOG.info("Recover file -- "+files[i]);
this.fileReader = new BufferedReader(new FileReader(files[i]));
List<StorageEntryWrapper> entryList = this.reader.recoverEntries(this.fileReader);
if(entryList.size() == 0)
continue;
storeEntries(entryList,modifier);
this.fileReader.close();
- if(!this.keepRecoverFiles)
+ if(!this.keepRecoverFiles){
+ LOG.info("Recovering file -- "+files[i]+" successful, delete file");
files[i].delete();
+ }
}catch (StorageException e) {
LOG.error("Can't store recover entries for file: "+files[i].getName()+" -- keep file "+e.getMessage(),e);
}catch (IOException e) {
@@ -126,7 +143,7 @@
}
}
- protected void storeEntries(final List<StorageEntryWrapper> entries, final StorageModifier modifier) throws StorageException{
+ protected void storeEntries(final List<StorageEntryWrapper> entries, final StorageModifier modifier) throws StorageException, IOException{
for (StorageEntryWrapper wrapper : entries) {
if(wrapper.getOperation() == StorageOperation.DELETE)
modifier.deleteEntry(wrapper);
@@ -134,12 +151,15 @@
modifier.insertEntry(wrapper);
else if(wrapper.getOperation() == StorageOperation.UPDATE)
modifier.updateEntry(wrapper);
-
-
+ modifier.forceWrite();
+
}
}
- protected synchronized void initialize() throws IOException {
+ /**
+ * @throws IOException
+ */
+ public synchronized void initialize() throws IOException {
if(this.recover)
return;
String filename = System.currentTimeMillis() + FILE_SUFFIX;
@@ -150,18 +170,32 @@
}
- protected void destroy() throws RecoverException {
+ /**
+ * @throws RecoverException
+ */
+ public synchronized void destroy() throws RecoverException {
if (this.fileWriter != null) {
this.lock.lock();
try {
+
this.fileWriter.flush();
this.fileWriter.close();
+ if(!this.keepRecoverFiles && this.currentRecoverFile != null)
+ this.currentRecoverFile.delete();
} catch (IOException e) {
throw new RecoverException("Can't close recover writer ", e);
} finally {
this.lock.unlock();
}
}
+ }
+
+ /**
+ * @return <code>true</code> if the RecoverController is initialized in recover mode, otherwise <code>false</code>
+ */
+ public boolean isRecovering() {
+
+ return this.recover;
}
Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverException.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverException.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverException.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverException.java Tue Jul 25 15:23:01 2006
@@ -16,11 +16,13 @@
package org.apache.lucene.gdata.storage.lucenestorage.recover;
+import org.apache.lucene.gdata.storage.StorageException;
+
/**
* @author Simon Willnauer
*
*/
-public class RecoverException extends Exception {
+public class RecoverException extends StorageException {
/**
*
Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverReader.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverReader.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverReader.java Tue Jul 25 15:23:01 2006
@@ -140,24 +140,24 @@
throw new RecoverException("Illegal metadata --- "+recoverString);
temp = tokenizer.nextToken();
if(temp == null)
- throw new RecoverException("Can't recover feed Id -- "+temp);
+ throw new RecoverException("Can't recover feed Id -- is null");
this.feedId = temp;
temp = tokenizer.nextToken();
if(temp == null)
- throw new RecoverException("Can't recover entry Id -- "+temp);
+ throw new RecoverException("Can't recover entry Id -- is null");
this.entryId = temp;
temp = tokenizer.nextToken();
try{
this.timestamp = Long.parseLong(temp);
}catch (Exception e) {
- throw new RecoverException("Can't recover timestamp -- "+temp,e);
+ throw new RecoverException("Can't recover timestamp -- is null",e);
}
if(this.operation != StorageOperation.DELETE){
temp = tokenizer.nextToken();
if(temp == null)
- throw new RecoverException("Can't recover service -- "+temp);
+ throw new RecoverException("Can't recover service -- is null");
if(!GDataServerRegistry.getRegistry().isServiceRegistered(temp))
throw new RecoverException("Service in recover metadata is not registered - "+temp);
this.config = GDataServerRegistry.getRegistry().getProvidedService(temp);
Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverWriter.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverWriter.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverWriter.java Tue Jul 25 15:23:01 2006
@@ -65,6 +65,7 @@
writer.write(META_DATA_ENTRY_SEPARATOR);
writer.write(STORAGE_OPERATION_SEPARATOR);
writer.write(META_DATA_ENTRY_SEPARATOR);
+ writer.flush();
}
Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/DateFormater.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/DateFormater.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/DateFormater.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/DateFormater.java Tue Jul 25 15:23:01 2006
@@ -40,21 +40,21 @@
*/
public class DateFormater {
private final Stack<SimpleDateFormat> objectStack = new Stack<SimpleDateFormat>();
-
+
private static final DateFormater formater = new DateFormater();
/**
* Date format as it is used in Http Last modified header (Tue, 15 Nov 1994
* 12:45:26 GMT)
*/
- public static String HTTP_HEADER_DATE_FORMAT = "EEE, d MMM yyyy HH:mm:ss z";
+ public final static String HTTP_HEADER_DATE_FORMAT = "EEE, d MMM yyyy HH:mm:ss z";
/**
* Date format as it is used in Http Last modified header (Tue, 15 Nov 1994
* 12:45:26 +0000)
*/
- public static String HTTP_HEADER_DATE_FORMAT_TIME_OFFSET = "EEE, d MMM yyyy HH:mm:ss Z";
+ public final static String HTTP_HEADER_DATE_FORMAT_TIME_OFFSET = "EEE, d MMM yyyy HH:mm:ss Z";
- private DateFormater() {
+ protected DateFormater() {
super();
}
@@ -74,8 +74,11 @@
"given parameters must not be null");
SimpleDateFormat inst = formater.getFormater();
inst.applyPattern(format);
- formater.returnFomater(inst);
- return inst.format(date);
+ try{
+ return inst.format(date);
+ }finally{
+ formater.returnFomater(inst);
+ }
}
/**
* Parses the given string into one of the specified formates
@@ -109,19 +112,26 @@
"given parameters must not be null");
SimpleDateFormat inst = formater.getFormater();
+ try{
inst.applyPattern(pattern);
return inst.parse(dateString);
+ }finally{
+ formater.returnFomater(inst);
+ }
+
}
- private SimpleDateFormat getFormater() {
+ protected SimpleDateFormat getFormater() {
if (this.objectStack.empty())
return new SimpleDateFormat(DateFormater.HTTP_HEADER_DATE_FORMAT,Locale.ENGLISH);
return this.objectStack.pop();
+
}
- private void returnFomater(final SimpleDateFormat format) {
+ protected void returnFomater(final SimpleDateFormat format) {
if (this.objectStack.size() <= 25)
this.objectStack.push(format);
+
}
}
Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/Pool.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/Pool.java?rev=425538&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/Pool.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/Pool.java Tue Jul 25 15:23:01 2006
@@ -0,0 +1,74 @@
+/**
+ * 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.utils;
+
+/**
+ * Basic interface to be implemented by ObjectPool implementations. Pools should
+ * provide a constructor with a
+ * {@link org.apache.lucene.gdata.utils.PoolObjectFactory} as a mandatory
+ * parameter to create and destory the pooled objects.
+ *
+ * @see org.apache.lucene.gdata.utils.PoolObjectFactory
+ *
+ * @author Simon Willnauer
+ * @param <Type> -
+ * the type of the pooled objects
+ *
+ */
+public interface Pool<Type> {
+ /**
+ * Return an object from the pool or create one if the pool is empty.
+ *
+ * @return - a pooled object
+ */
+ public abstract Type aquire();
+
+ /**
+ * Adds a previously aquired object to the pool. If the pool has already
+ * been closed or if the pool has already reached his size the released
+ * object will be destroyed using
+ * {@link PoolObjectFactory#destroyInstance(Object)} method.
+ *
+ * @param type -
+ * the previously aquired object
+ */
+ public abstract void release(final Type type);
+
+ /**
+ * @return - the defined size of the pool
+ */
+ public abstract int getSize();
+
+ /**
+ * @return - the expire time of the objects in the pool if defined
+ */
+ public abstract long getExpireTime();
+
+ /**
+ * @return <code>true</code> if and only if the pool uses an expire
+ * mechanismn, otherwith <code>false</code>
+ */
+ public abstract boolean expires();
+
+ /**
+ * releases all pooled objects using
+ * {@link PoolObjectFactory#destroyInstance(Object)} method. The pool can not
+ * be reused after this method has been called
+ */
+ public abstract void destroy();
+
+}
Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/Pool.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/Pool.java
------------------------------------------------------------------------------
svn:executable = *
Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/PoolObjectFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/PoolObjectFactory.java?rev=425538&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/PoolObjectFactory.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/PoolObjectFactory.java Tue Jul 25 15:23:01 2006
@@ -0,0 +1,53 @@
+/**
+ * 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.utils;
+
+/**
+ * <p>
+ * This interface enables {@link org.apache.lucene.gdata.utils.Pool} users to
+ * build a custom creation and destroy mechanismn for pooled objects.
+ * Implementations can use standart creation to prevent the pool from using
+ * reflection to create objects of the specific type. This implementation
+ * seperates the Pool implementation from the creation or the destruction of a
+ * pooled type.
+ * </p>
+ * <p>
+ * The destroy method can be used to close datasource connections or release
+ * resources if the object will be removed from the pool
+ * </p>
+ *
+ *
+ * @see org.apache.lucene.gdata.utils.Pool
+ * @author Simon Willnauer
+ * @param <Type> -
+ * the type to be created
+ *
+ */
+public interface PoolObjectFactory<Type> {
+
+ /**
+ * @return an instance of the specified Type
+ */
+ public abstract Type getInstance();
+
+ /**
+ * destroys the given instance
+ * @param type - the object to destroy / release all resources
+ */
+ public abstract void destroyInstance(Type type);
+
+}
Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/PoolObjectFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/PoolObjectFactory.java
------------------------------------------------------------------------------
svn:executable = *
Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/SimpleObjectPool.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/SimpleObjectPool.java?rev=425538&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/SimpleObjectPool.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/SimpleObjectPool.java Tue Jul 25 15:23:01 2006
@@ -0,0 +1,175 @@
+/**
+ * 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.utils;
+
+import java.util.Stack;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A Simple implementation of the {@link org.apache.lucene.gdata.utils.Pool}
+ * interface using a {@link java.util.Stack} as a buffer for the pooled objects.
+ * This implementation does not provide any timeout mechanismn. Objects will
+ * stay inside the pool until the pool is destroyed.
+ * <p>
+ * If any object will be released e.g. handover to the pool and the pool has
+ * already enought objects in the pool the released object will be destroyed. If
+ * the pool is empty a new Object will be created.
+ * </p>
+ * <p>
+ * This implementation does not track any references to the objects aquired by
+ * any other resource. The objects must be destroyed manually if not released to
+ * the pool after aquired.
+ * </p>
+ *
+ * @author Simon Willnauer
+ * @param <Type>
+ *
+ */
+public class SimpleObjectPool<Type> implements Pool<Type> {
+ private static final Log LOG = LogFactory.getLog(SimpleObjectPool.class);
+ private volatile boolean isDestroyed = false;
+
+ private final PoolObjectFactory<Type> factory;
+
+ static final int DEFAULTSIZE = 5;
+ static final int MINIMALSIZE = 1;
+
+ private final int size;
+
+ private final Stack<Type> pool;
+
+ private final ReentrantReadWriteLock masterLock = new ReentrantReadWriteLock();
+
+ private final Lock readLock = this.masterLock.readLock();
+
+ private final Lock writeLock = this.masterLock.writeLock();
+
+ /**
+ * Constructs a new {@link SimpleObjectPool} and sets the ObjectFactory and the pool size
+ * @param size - the maximum size of the pool
+ * @param factory - factory to create and destroy pooled objects
+ *
+ */
+ public SimpleObjectPool(int size, PoolObjectFactory<Type> factory) {
+ if (factory == null)
+ throw new IllegalArgumentException("Factory must not be null");
+ this.factory = factory;
+ this.size = size < MINIMALSIZE ? MINIMALSIZE : size;
+ this.pool = new Stack<Type>();
+ for (int i = 0; i < this.size; i++) {
+ this.pool.push(this.factory.getInstance());
+ }
+ }
+ /**
+ * @param factory
+ */
+ public SimpleObjectPool(PoolObjectFactory<Type> factory) {
+ this(DEFAULTSIZE,factory);
+
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.utils.Pool#aquire()
+ */
+ public Type aquire() {
+ // fail if writelock is aquired
+ if (this.readLock.tryLock()) {
+ try {
+ if (this.isDestroyed)
+ throw new IllegalStateException(
+ "The pool has already been closed");
+ if (this.pool.isEmpty())
+ return this.factory.getInstance();
+ return this.pool.pop();
+ } finally {
+ this.readLock.unlock();
+ }
+ }
+ throw new IllegalStateException("The pool has already been closed");
+ }
+
+ /**
+ *
+ * @param type - generic type
+ * @see org.apache.lucene.gdata.utils.Pool#release(Object)
+ */
+ public void release(Type type) {
+ // fail if writelock is aquired
+ if (this.readLock.tryLock()) {
+ try {
+ if (this.pool.size() < this.size && !this.isDestroyed)
+ this.pool.push(type);
+ else
+ this.factory.destroyInstance(type);
+ } finally {
+ this.readLock.unlock();
+ }
+ return;
+ }
+ // enable object need to be destoryed
+ this.factory.destroyInstance(type);
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.utils.Pool#getSize()
+ */
+ public int getSize() {
+
+ return this.size;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.utils.Pool#getExpireTime()
+ */
+ public long getExpireTime() {
+
+ return 0;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.utils.Pool#expires()
+ */
+ public boolean expires() {
+
+ return false;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.utils.Pool#destroy()
+ */
+ public void destroy() {
+ this.writeLock.lock();
+ try {
+ if (this.isDestroyed)
+ return;
+ this.isDestroyed = true;
+ LOG.info("Destroy all elements in the pool -- poolsize: "+this.pool.size());
+ for (Type type : this.pool) {
+ this.factory.destroyInstance(type);
+ }
+ this.pool.clear();
+ } finally {
+ this.writeLock.unlock();
+ }
+
+ }
+
+}
Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/SimpleObjectPool.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/SimpleObjectPool.java
------------------------------------------------------------------------------
svn:executable = *
Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/SimpleSaxErrorHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/SimpleSaxErrorHandler.java?rev=425538&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/SimpleSaxErrorHandler.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/SimpleSaxErrorHandler.java Tue Jul 25 15:23:01 2006
@@ -0,0 +1,52 @@
+/**
+ * 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.utils;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * For use with Digester to throw exceptions on errors
+ * @author Simon Willnauer
+ *
+ */
+public final class SimpleSaxErrorHandler implements ErrorHandler{
+
+ /**
+ * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
+ */
+ public void warning(SAXParseException arg0) throws SAXException {
+ //
+ }
+
+ /**
+ * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
+ */
+ public void error(SAXParseException arg0) throws SAXException {
+
+ throw new SAXException("ERROR: Can not parse XML Document -- "+arg0.getMessage(),arg0);
+ }
+
+ /**
+ * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
+ */
+ public void fatalError(SAXParseException arg0) throws SAXException {
+ throw new SAXException("FATAL ERROR: Can not parse XML Document -- "+arg0.getMessage(),arg0);
+ }
+
+}
\ No newline at end of file
Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/SimpleSaxErrorHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/SimpleSaxErrorHandler.java
------------------------------------------------------------------------------
svn:executable = *
Added: lucene/java/trunk/contrib/gdata-server/src/test/gdata-account.xsd
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/gdata-account.xsd?rev=425538&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/gdata-account.xsd (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/gdata-account.xsd Tue Jul 25 15:23:01 2006
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:element name="password">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:minLength value="5" />
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+ <xs:element name="account-name">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:whiteSpace value="collapse" />
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:element name="email-address" type="xs:string" />
+ <xs:element name="url" type="xs:anyURI" />
+ <xs:element name="name" type="xs:string" />
+ <xs:element name="account-role">
+ <xs:simpleType>
+ <xs:restriction base="xs:positiveInteger">
+ <xs:fractionDigits value="2" />
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+
+ <xs:element name="account-owner">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="name" />
+ <xs:element ref="email-address" />
+ <xs:element ref="url" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="account">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="account-name" />
+ <xs:element ref="password" />
+ <xs:element ref="account-role" />
+ <xs:element ref="account-owner" minOccurs="0" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
\ No newline at end of file
Propchange: lucene/java/trunk/contrib/gdata-server/src/test/gdata-account.xsd
------------------------------------------------------------------------------
svn:executable = *
Modified: lucene/java/trunk/contrib/gdata-server/src/test/gdata-config.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/gdata-config.xml?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/gdata-config.xml (original)
+++ lucene/java/trunk/contrib/gdata-server/src/test/gdata-config.xml Tue Jul 25 15:23:01 2006
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<gdata>
- <service name="feed" public="true">
- <feed-class>com.google.gdata.data.Feed</feed-class>
- <entry-class>com.google.gdata.data.Entry</entry-class>
- <extension-profile>
- com.google.gdata.data.ExtensionProfile
- </extension-profile>
- </service>
- <service name="calendar" public="true">
- <feed-class>
- com.google.gdata.data.extensions.EventFeed
- </feed-class>
- <entry-class>
- com.google.gdata.data.extensions.EventEntry
- </entry-class>
- <extension-profile>
- com.google.gdata.data.ExtensionProfile
- </extension-profile>
- </service>
- <server-components>
- <component>
- org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController
- </component>
- <component>
- org.apache.lucene.gdata.servlet.handler.DefaultRequestHandlerFactory
- </component>
- <component>
- org.apache.lucene.gdata.server.ServiceFactory
- </component>
- <component>
- org.apache.lucene.gdata.server.authentication.BlowfishAuthenticationController
- </component>
- </server-components>
-</gdata>
\ No newline at end of file
Modified: lucene/java/trunk/contrib/gdata-server/src/test/lucenestorage.properties.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/lucenestorage.properties.xml?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/lucenestorage.properties.xml (original)
+++ lucene/java/trunk/contrib/gdata-server/src/test/lucenestorage.properties.xml Tue Jul 25 15:23:01 2006
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
-<properties>
-<comment>Lucene Storage Properties</comment>
-<entry key="gdata.server.storage.lucene.buffersize">20</entry>
-<entry key="gdata.server.storage.lucene.optimizeInterval">20</entry>
-<entry key="gdata.server.storage.lucene.persistFactor">20</entry>
-<entry key="gdata.server.storage.lucene.directory.ramDirectory">true</entry>
-<entry key="gdata.server.storage.lucene.directory">/tmp/storage/</entry>
-<entry key="gdata.server.storage.lucene.recover">true</entry>
-<entry key="gdata.server.storage.lucene.recover.keepFiles">false</entry>
-</properties>
Modified: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/data/TestGDataUser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/data/TestGDataUser.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/data/TestGDataUser.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/data/TestGDataUser.java Tue Jul 25 15:23:01 2006
@@ -1,5 +1,8 @@
package org.apache.lucene.gdata.data;
+import java.net.MalformedURLException;
+import java.net.URL;
+
import org.apache.lucene.gdata.data.GDataAccount.AccountRole;
import junit.framework.TestCase;
@@ -59,6 +62,7 @@
assertEquals(4,this.user.getRoles().size());
}
+
Modified: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/TestGDataRequest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/TestGDataRequest.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/TestGDataRequest.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/TestGDataRequest.java Tue Jul 25 15:23:01 2006
@@ -15,6 +15,9 @@
*/
package org.apache.lucene.gdata.server;
+import java.util.Enumeration;
+import java.util.StringTokenizer;
+
import javax.servlet.http.HttpServletRequest;
import junit.framework.TestCase;
@@ -39,17 +42,15 @@
private MockControl control;
private GDataRequest feedRequest;
- static{
- try {
- GDataServerRegistry.getRegistry().registerComponent(StorageStub.class);
- } catch (RegistryException e) {
-
- e.printStackTrace();
- }
- }
+
@Override
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception {
+ try{
+ GDataServerRegistry.getRegistry().registerComponent(StorageStub.class,null);
+ }catch (Exception e) {
+
+ }
ProvidedService configurator = new ProvidedServiceStub();
GDataServerRegistry.getRegistry().registerService(configurator);
@@ -225,7 +226,7 @@
String feedAndEntryID = "/feed/entryid";
String queryString = "max-results=25";
this.control.expectAndDefaultReturn(this.request.getHeader("Host"),host);
- this.control.expectAndDefaultReturn(this.request.getRequestURI(),"/host/feed/entryId/15");
+ this.control.expectAndDefaultReturn(this.request.getRequestURI(),"/host/feed/entryId/15/");
this.control.expectAndDefaultReturn(this.request.getPathInfo(),"/feed/entryId/15");
this.control.expectAndReturn(this.request.getParameter("max-results"),"25",2);
this.control.expectAndDefaultReturn(this.request.getParameter("alt"),
@@ -235,7 +236,6 @@
this.control.replay();
this.feedRequest.initializeRequest();
String selfID = "http://"+host+"/host/feed/entryId/15?"+queryString;
-
assertEquals("Self ID",selfID,this.feedRequest.getSelfId());
this.control.reset();
@@ -354,67 +354,95 @@
this.control.replay();
assertEquals("bla",this.feedRequest.getAuthToken());
this.control.verify();
+ this.control.reset();
}
public void testGetNextId() throws GDataRequestException{
-// String host = "www.apache.org";
-// String feedAndEntryID = "/feed/entryid";
-// String queryString = "?max-results=25";
-// String startIndex = "&start-index=26";
-// this.control.expectAndDefaultReturn(this.request.getHeader("Host"),host);
-// this.control.expectAndDefaultReturn(this.request.getRequestURI(),"/feed/");
-// this.control.expectAndDefaultReturn(this.request.getPathInfo(),"/feed/");
-// this.control.expectAndReturn(this.request.getParameter("max-results"),"25",2);
-// this.control.expectAndReturn(this.request.getParameter("start-index"),null);
-// this.control.expectAndDefaultReturn(this.request.getParameter("alt"),
-// null);
-// this.control.expectAndDefaultReturn(this.request.getQueryString(),
-// queryString);
-// this.control.replay();
-// this.feedRequest.initializeRequest();
-// String nextID = "http://"+host+"/feed/"+queryString+startIndex;
-//
-// assertEquals("Next ID",nextID,this.feedRequest.getNextId());
-// this.control.reset();
-
-
-// queryString = "?alt=rss&max-results=25";
-//
-// this.control.expectAndDefaultReturn(this.request.getHeader("Host"),host);
-// this.control.expectAndDefaultReturn(this.request.getRequestURI(),"/feed/");
-// this.control.expectAndDefaultReturn(this.request.getPathInfo(),"/feed/");
-// this.control.expectAndReturn(this.request.getParameter("max-results"),"25",2);
-// this.control.expectAndReturn(this.request.getParameter("start-index"),"26",2);
-// this.control.expectAndDefaultReturn(this.request.getParameter("alt"),
-// null);
-// this.control.expectAndDefaultReturn(this.request.getQueryString(),
-// queryString+startIndex);
-// Enumeration e =
-// this.control.expectAndDefaultReturn(this.request.getParameterNames(),)
-//
-//
-// this.control.replay();
-// this.feedRequest.initializeRequest();
-// startIndex = "&start-index=51";
-// nextID = "http://"+host+"/feed"+queryString+startIndex;
-//
-// assertEquals("Next ID 51",nextID,this.feedRequest.getNextId());
-// this.control.reset();
-//
-// queryString = "";
-// this.control.expectAndDefaultReturn(this.request.getHeader("Host"),host);
-// this.control.expectAndDefaultReturn(this.request.getPathInfo(),"/feed/entryId/15");
-// this.control.expectAndDefaultReturn(this.request.getParameter("max-results"),null);
-// this.control.expectAndDefaultReturn(this.request.getParameter("alt"),
-// null);
-// this.control.expectAndDefaultReturn(this.request.getQueryString(),
-// null);
-// this.control.replay();
-// this.feedRequest.initializeRequest();
-// String selfID = "http://"+host+"/feed"+"?max-results=25";
-//
-// assertEquals("Self ID",selfID,this.feedRequest.getSelfId());
-// this.control.reset();
+ String host = "www.apache.org";
+ String feedAndEntryID = "/feed/entryid";
+ String queryString = "?max-results=25";
+ String startIndex = "&start-index=26";
+ Enumeration enu = new StringTokenizer("max-results",",");
+
+
+ this.control.expectAndDefaultReturn(this.request.getParameterNames(),enu);
+ this.control.expectAndDefaultReturn(this.request.getHeader("Host"),host);
+ this.control.expectAndDefaultReturn(this.request.getRequestURI(),"/feed/");
+ this.control.expectAndDefaultReturn(this.request.getPathInfo(),"/feed/");
+ this.control.expectAndReturn(this.request.getParameter("max-results"),"25",4);
+ this.control.expectAndReturn(this.request.getParameter("start-index"),null);
+ this.control.expectAndDefaultReturn(this.request.getParameter("alt"),
+ null);
+ this.control.expectAndDefaultReturn(this.request.getQueryString(),
+ queryString);
+ this.control.replay();
+
+ this.feedRequest.initializeRequest();
+ String nextID = "http://"+host+"/feed"+queryString+startIndex;
+
+ assertEquals("Next ID",nextID,this.feedRequest.getNextId());
+ this.control.verify();
+ this.control.reset();
+
+ enu = new StringTokenizer("alt,max-results,start-index",",");
+ queryString = "?alt=rss&max-results=25";
+
+ this.control.expectAndDefaultReturn(this.request.getHeader("Host"),host);
+ this.control.expectAndDefaultReturn(this.request.getRequestURI(),"/feed/");
+ this.control.expectAndDefaultReturn(this.request.getPathInfo(),"/feed/");
+ this.control.expectAndReturn(this.request.getParameter("max-results"),"25",4);
+ this.control.expectAndReturn(this.request.getParameter("start-index"),"26",4);
+ this.control.expectAndDefaultReturn(this.request.getParameter("alt"),
+ "rss");
+ this.control.expectAndDefaultReturn(this.request.getQueryString(),
+ queryString+startIndex);
+
+ this.control.expectAndDefaultReturn(this.request.getParameterNames(),enu);
+
+
+ this.control.replay();
+ this.feedRequest.initializeRequest();
+ startIndex = "&start-index=51";
+ nextID = "http://"+host+"/feed"+queryString+startIndex;
+
+ assertEquals("Next ID 51",nextID,this.feedRequest.getNextId());
+ this.control.reset();
+
+ queryString = "";
+ this.control.expectAndDefaultReturn(this.request.getHeader("Host"),host);
+ this.control.expectAndDefaultReturn(this.request.getRequestURI(),"/feed/");
+ this.control.expectAndDefaultReturn(this.request.getPathInfo(),"/feed/entryId/15");
+ this.control.expectAndDefaultReturn(this.request.getParameter("max-results"),null);
+ this.control.expectAndDefaultReturn(this.request.getParameter("alt"),
+ null);
+ this.control.expectAndDefaultReturn(this.request.getQueryString(),
+ null);
+ this.control.replay();
+ this.feedRequest.initializeRequest();
+ String selfID = "http://"+host+"/feed"+"?max-results=25";
+
+ assertEquals("Self ID",selfID,this.feedRequest.getSelfId());
+ this.control.reset();
}
+
+ public void testGetContextPath(){
+ String host = "www.apache.org";
+ this.control.expectAndDefaultReturn(this.request.getHeader("Host"),host);
+ this.control.expectAndDefaultReturn(this.request.getRequestURI(),"/feed/id/");
+ this.control.expectAndDefaultReturn(this.request.getPathInfo(),"/feed/id/");
+ this.control.replay();
+ String result = "http://"+host+"/feed/id/";
+ assertEquals(result,this.feedRequest.getContextPath());
+ this.control.verify();
+ this.control.reset();
+ this.control.expectAndDefaultReturn(this.request.getHeader("Host"),host);
+ this.control.expectAndDefaultReturn(this.request.getRequestURI(),"/feed/id");
+ this.control.expectAndDefaultReturn(this.request.getPathInfo(),"/feed/id");
+ this.control.replay();
+
+ assertEquals(result,this.feedRequest.getContextPath());
+ this.control.verify();
+
+ }
}
Modified: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/administration/TestAccountBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/administration/TestAccountBuilder.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/administration/TestAccountBuilder.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/administration/TestAccountBuilder.java Tue Jul 25 15:23:01 2006
@@ -13,6 +13,8 @@
public class TestAccountBuilder extends TestCase {
private StringReader reader;
private String inputXML;
+ private StringReader invalidReader;
+ private String invalidInputXML;
protected void setUp() throws Exception {
this.inputXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<account>" +
@@ -27,6 +29,18 @@
"</account>";
this.reader = new StringReader(this.inputXML);
+ this.invalidInputXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<account>" +
+ "<account-name>simon</account-name>" +
+ "<account-role>6</account-role>" +
+ "<account-owner>" +
+ "<name>simon willnauer</name>" +
+ "<email-address>simon@gmail.com</email-address>" +
+ "<url>http://www.javawithchopsticks.de</url>" +
+ "</account-owner>" +
+ "</account>";
+
+ this.invalidReader = new StringReader(this.invalidInputXML);
}
@@ -49,6 +63,15 @@
assertTrue(user.isUserInRole(AccountRole.FEEDAMINISTRATOR));
assertFalse(user.isUserInRole(AccountRole.USERADMINISTRATOR));
+ }
+
+ public void testBuildUserWrongXML() throws IOException{
+ try{
+ AccountBuilder.buildAccount(this.invalidReader);
+ fail("invalid xml");
+ }catch (SAXException e) {
+
+ }
}
}
Modified: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/authentication/TestBlowfishAuthenticationController.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/authentication/TestBlowfishAuthenticationController.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/authentication/TestBlowfishAuthenticationController.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/authentication/TestBlowfishAuthenticationController.java Tue Jul 25 15:23:01 2006
@@ -84,7 +84,7 @@
}catch (Exception e) {
// TODO: handle exception
}
- this.controller.setMinuteOffset(0);
+ this.controller.setLoginTimeout(0);
assertFalse(this.controller.authenticateToken(token,this.clientIp,AccountRole.ENTRYAMINISTRATOR,this.accountName));
}
Modified: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/registry/TestFeedRegistry.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/registry/TestFeedRegistry.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/registry/TestFeedRegistry.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/registry/TestFeedRegistry.java Tue Jul 25 15:23:01 2006
@@ -15,6 +15,8 @@
*/
package org.apache.lucene.gdata.server.registry;
+import junit.framework.TestCase;
+
import org.apache.lucene.gdata.server.ServiceFactory;
import org.apache.lucene.gdata.servlet.handler.DefaultRequestHandlerFactory;
import org.apache.lucene.gdata.servlet.handler.RequestHandlerFactory;
@@ -22,111 +24,130 @@
import org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController;
import com.google.gdata.data.Entry;
+import com.google.gdata.data.ExtensionProfile;
import com.google.gdata.data.Feed;
-import junit.framework.TestCase;
-
/**
* @author Simon Willnauer
- *
+ *
*/
public class TestFeedRegistry extends TestCase {
- private GDataServerRegistry reg;
- private ProvidedServiceConfig configurator;
- @Override
- protected void setUp(){
- this.reg = GDataServerRegistry.getRegistry();
- this.configurator = new ProvidedServiceConfig();
+ private GDataServerRegistry reg;
+
+ private ProvidedServiceConfig configurator;
+
+ @Override
+ protected void setUp() {
+ this.reg = GDataServerRegistry.getRegistry();
+ this.configurator = new ProvidedServiceConfig();
this.configurator.setEntryType(Entry.class);
this.configurator.setFeedType(Feed.class);
- }
- /**
- * @see junit.framework.TestCase#tearDown()
- */
- @Override
- protected void tearDown() throws Exception {
- this.reg.flushRegistry();
- }
- /**
- * Test method for 'org.apache.lucene.gdata.server.registry.FeedRegistry.getRegistry()'
- */
- public void testGetRegistry() {
-
- GDataServerRegistry reg1 = GDataServerRegistry.getRegistry();
- assertEquals("test singleton",this.reg,reg1);
- }
-
- /**
- * Test method for 'org.apache.lucene.gdata.server.registry.FeedRegistry.registerFeed(FeedInstanceConfigurator)'
- */
- public void testRegisterService() {
- String service = "service";
- registerService(service);
- assertEquals("Registered Configurator",this.configurator,this.reg.getProvidedService(service));
- assertNull("not registered Configurator",this.reg.getProvidedService("something"));
- try{
- this.reg.getProvidedService(null);
- fail("Exception expected");
- }catch (IllegalArgumentException e) {
- //
- }
- }
-
- /**
- * Test method for 'org.apache.lucene.gdata.server.registry.FeedRegistry.getFeedConfigurator(String)'
- */
- public void testFlushRegistry() {
+ this.configurator.setExtensionProfile(new ExtensionProfile());
+ }
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ this.reg.flushRegistry();
+
+ }
+
+ /**
+ * Test method for
+ * 'org.apache.lucene.gdata.server.registry.FeedRegistry.getRegistry()'
+ */
+ public void testGetRegistry() {
+
+ GDataServerRegistry reg1 = GDataServerRegistry.getRegistry();
+ assertEquals("test singleton", this.reg, reg1);
+ }
+
+ /**
+ * Test method for
+ * 'org.apache.lucene.gdata.server.registry.FeedRegistry.registerFeed(FeedInstanceConfigurator)'
+ */
+ public void testRegisterService() {
String service = "service";
registerService(service);
-
- assertEquals("Registered Configurator",this.configurator,this.reg.getProvidedService(service));
- this.reg.flushRegistry();
- assertNull("Registry flushed",this.reg.getProvidedService(service));
-
-
- }
-
- /**
- *
- */
- public void testIsFeedRegistered(){
+ assertEquals("Registered Configurator", this.configurator, this.reg
+ .getProvidedService(service));
+ assertNull("not registered Configurator", this.reg
+ .getProvidedService("something"));
+ try {
+ this.reg.getProvidedService(null);
+ fail("Exception expected");
+ } catch (IllegalArgumentException e) {
+ //
+ }
+ }
+
+ /**
+ * Test method for
+ * 'org.apache.lucene.gdata.server.registry.FeedRegistry.getFeedConfigurator(String)'
+ */
+ public void testFlushRegistry() {
String service = "service";
registerService(service);
- assertTrue("Feed is registerd",this.reg.isServiceRegistered(service));
- assertFalse("null Feed is not registerd",this.reg.isServiceRegistered(null));
- assertFalse("Feed is not registerd",this.reg.isServiceRegistered("something"));
-
- }
-
- private void registerService(String servicename){
-
- this.configurator.setName(servicename);
- this.reg.registerService(this.configurator);
- }
-
- public void testRegisterComponent() throws RegistryException{
+
+ assertEquals("Registered Configurator", this.configurator, this.reg
+ .getProvidedService(service));
+ this.reg.flushRegistry();
+ assertNull("Registry flushed", this.reg.getProvidedService(service));
+
+ }
+
+ /**
+ *
+ */
+ public void testIsFeedRegistered() {
+ String service = "service";
+ registerService(service);
+ assertTrue("Feed is registerd", this.reg.isServiceRegistered(service));
+ assertFalse("null Feed is not registerd", this.reg
+ .isServiceRegistered(null));
+ assertFalse("Feed is not registerd", this.reg
+ .isServiceRegistered("something"));
+
+ }
+
+ private void registerService(String servicename) {
+
+ this.configurator.setName(servicename);
+ this.reg.registerService(this.configurator);
+ }
+
+ public void testRegisterComponent() throws RegistryException {
try {
- this.reg.registerComponent(StorageController.class);
+ this.reg.registerComponent(StorageController.class, null);
fail("RegistryException expected");
} catch (RegistryException e) {
- //
+ //
+ }
+ new GDataRequestListener();
+ try {
+ this.reg.registerComponent(StorageCoreController.class, null);
+ fail("no config");
+ } catch (Exception e) {
+ // TODO: handle exception
}
- this.reg.registerComponent(StorageCoreController.class);
-
- this.reg.registerComponent(DefaultRequestHandlerFactory.class);
- RequestHandlerFactory factory = this.reg.lookup(RequestHandlerFactory.class,ComponentType.REQUESTHANDLERFACTORY);
- try{
- this.reg.registerComponent(DefaultRequestHandlerFactory.class);
- fail("RegistryException expected");
+ this.reg.registerComponent(DefaultRequestHandlerFactory.class, null);
+ RequestHandlerFactory factory = this.reg.lookup(
+ RequestHandlerFactory.class,
+ ComponentType.REQUESTHANDLERFACTORY);
+ try {
+ this.reg
+ .registerComponent(DefaultRequestHandlerFactory.class, null);
+ fail("RegistryException expected");
} catch (RegistryException e) {
- //
+ //
}
- this.reg.registerComponent(ServiceFactory.class);
- ServiceFactory servicefactory = this.reg.lookup(ServiceFactory.class,ComponentType.SERVICEFACTORY);
+ this.reg.registerComponent(ServiceFactory.class, null);
+ ServiceFactory servicefactory = this.reg.lookup(ServiceFactory.class,
+ ComponentType.SERVICEFACTORY);
assertNotNull(servicefactory);
assertNotNull(factory);
-
-
}
}
Modified: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/handler/TestAbstractFeedHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/handler/TestAbstractFeedHandler.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/handler/TestAbstractFeedHandler.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/handler/TestAbstractFeedHandler.java Tue Jul 25 15:23:01 2006
@@ -61,8 +61,8 @@
try {
- GDataServerRegistry.getRegistry().registerComponent(StorageStub.class);
- GDataServerRegistry.getRegistry().registerComponent(ServiceFactoryStub.class);
+ GDataServerRegistry.getRegistry().registerComponent(StorageStub.class,null);
+ GDataServerRegistry.getRegistry().registerComponent(ServiceFactoryStub.class,null);
} catch (RegistryException e) {
e.printStackTrace();
Modified: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/TestIDGenerator.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/TestIDGenerator.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/TestIDGenerator.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/TestIDGenerator.java Tue Jul 25 15:23:01 2006
@@ -24,8 +24,10 @@
}
@Override
- protected void tearDown() throws Exception {
- this.idgen.stopIDGenerator();
+ protected void tearDown() throws Exception {
+
+ this.idgen.stopIDGenerator();
+
}
/**
Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageCoreControllerStub.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageCoreControllerStub.java?rev=425538&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageCoreControllerStub.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageCoreControllerStub.java Tue Jul 25 15:23:01 2006
@@ -0,0 +1,212 @@
+/**
+ * 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 java.security.NoSuchAlgorithmException;
+
+import org.apache.lucene.gdata.server.registry.Component;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.storage.IDGenerator;
+import org.apache.lucene.gdata.storage.Storage;
+import org.apache.lucene.gdata.storage.StorageController;
+import org.apache.lucene.gdata.storage.StorageException;
+import org.apache.lucene.gdata.storage.lucenestorage.util.ReferenceCounter;
+import org.apache.lucene.index.IndexModifier;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+@Component(componentType = ComponentType.STORAGECONTROLLER)
+public class StorageCoreControllerStub extends StorageCoreController {
+ private final IDGenerator idGenerator;
+
+
+ public StorageCoreControllerStub() throws IOException, StorageException {
+ try{
+ this.idGenerator = new IDGenerator(5);
+ }catch (NoSuchAlgorithmException e) {
+ throw new StorageException(e);
+ }
+
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#createIndexModifier()
+ */
+ @Override
+ protected IndexModifier createIndexModifier() throws IOException {
+
+ return null;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#forceWrite()
+ */
+ @Override
+ public void forceWrite() throws IOException {
+
+
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#getDirectory()
+ */
+ @Override
+ protected Directory getDirectory() {
+
+ return null;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#getBufferSize()
+ */
+ @Override
+ public int getBufferSize() {
+
+ return 1;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#getStorageModifier()
+ */
+ @Override
+ protected StorageModifier getStorageModifier() {
+
+ try {
+ return new StorageModifierStub();
+ } catch (IOException e) {
+
+ e.printStackTrace();
+ } catch (StorageException e) {
+
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#getPersistFactor()
+ */
+ @Override
+ public int getPersistFactor() {
+
+ return 1;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#getStorageQuery()
+ */
+ @Override
+ protected ReferenceCounter<StorageQuery> getStorageQuery() {
+
+ ReferenceCounter<StorageQuery> retVal = new ReferenceCounter<StorageQuery>(new StorageQueryStub(null,null)){
+
+ @Override
+ protected void close() {
+ //
+ }
+
+ };
+ retVal.increamentReference();
+ retVal.increamentReference();
+ return retVal;
+
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#registerNewStorageQuery()
+ */
+ @Override
+ protected void registerNewStorageQuery() throws IOException {
+
+
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#releaseId()
+ */
+ @Override
+ public synchronized String releaseId() throws StorageException {
+
+ try {
+ return this.idGenerator.getUID();
+ } catch (InterruptedException e) {
+
+ throw new StorageException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#releaseNewStorageBuffer()
+ */
+ @Override
+ protected StorageBuffer releaseNewStorageBuffer() {
+
+ return null;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#setBufferSize(int)
+ */
+ @Override
+ public void setBufferSize(int storageBufferSize) {
+
+
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#setPersistFactor(int)
+ */
+ @Override
+ public void setPersistFactor(int storagePersistFactor) {
+
+
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#destroy()
+ */
+ @Override
+ public void destroy() {
+
+ this.idGenerator.stopIDGenerator();
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#getStorage()
+ */
+ @Override
+ public Storage getStorage() throws StorageException {
+
+ return new StorageImplementation();
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController#initialize()
+ */
+ @Override
+ public void initialize() {
+// this.setStorageDir(new RAMDirectory());
+// super.initialize();
+ }
+
+
+}
Propchange: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageCoreControllerStub.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageCoreControllerStub.java
------------------------------------------------------------------------------
svn:executable = *
Modified: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageModifierStub.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageModifierStub.java?rev=425538&r1=425537&r2=425538&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageModifierStub.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageModifierStub.java Tue Jul 25 15:23:01 2006
@@ -32,7 +32,10 @@
*
*/
public class StorageModifierStub extends StorageModifier {
-
+ public boolean throwException = false;
+ public StorageModifierStub() throws IOException, StorageException{
+ super(new StorageCoreControllerStub(), new IndexModifier(new RAMDirectory(),new StandardAnalyzer(),true), new StorageBuffer(1),1, 1);
+ }
/**
* @param controller
* @param modifier
@@ -46,7 +49,7 @@
IndexModifier modifier, StorageBuffer buffer, int persitsFactor,
int optimizeInterval) throws IOException, StorageException {
- super(new StorageCoreController(), new IndexModifier(new RAMDirectory(),new StandardAnalyzer(),true), new StorageBuffer(1),1, 1);
+ super(new StorageCoreControllerStub(), new IndexModifier(new RAMDirectory(),new StandardAnalyzer(),true), new StorageBuffer(1),1, 1);
// TODO Auto-generated constructor stub
}
@@ -56,7 +59,8 @@
*/
@Override
protected void close() throws IOException {
-
+ if(throwException)
+ throw new IOException();
}
@@ -65,7 +69,8 @@
*/
@Override
public void createAccount(StorageAccountWrapper account) throws StorageException {
-
+ if(throwException)
+ throw new StorageException();
}
@@ -74,7 +79,8 @@
*/
@Override
public void createFeed(StorageFeedWrapper wrapper) throws StorageException {
-
+ if(throwException)
+ throw new StorageException();
}
@@ -83,7 +89,8 @@
*/
@Override
public void deleteAccount(String accountName) throws StorageException {
-
+ if(throwException)
+ throw new StorageException();
}
@@ -92,7 +99,8 @@
*/
@Override
public void deleteEntry(StorageEntryWrapper wrapper) throws StorageException {
-
+ if(throwException)
+ throw new StorageException();
}
@@ -101,7 +109,8 @@
*/
@Override
public void deleteFeed(String feedId) throws StorageException {
-
+ if(throwException)
+ throw new StorageException();
}
@@ -109,8 +118,9 @@
* @see org.apache.lucene.gdata.storage.lucenestorage.StorageModifier#forceWrite()
*/
@Override
- protected void forceWrite() throws IOException {
-
+ public void forceWrite() throws IOException {
+ if(throwException)
+ throw new IOException();
}
@@ -119,7 +129,8 @@
*/
@Override
public void insertEntry(StorageEntryWrapper wrapper) throws StorageException {
-
+ if(throwException)
+ throw new StorageException();
}
@@ -128,7 +139,8 @@
*/
@Override
public void updateAccount(StorageAccountWrapper user) throws StorageException {
-
+ if(throwException)
+ throw new StorageException();
}
@@ -137,8 +149,10 @@
*/
@Override
public void updateEntry(StorageEntryWrapper wrapper) throws StorageException {
-
-
+ if(throwException)
+ throw new StorageException();
+ if(wrapper != null)
+ wrapper.getEntry();
}
/**
@@ -146,7 +160,8 @@
*/
@Override
public void updateFeed(StorageFeedWrapper wrapper) throws StorageException {
-
+ if(throwException)
+ throw new StorageException();
}
Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageQueryStub.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageQueryStub.java?rev=425538&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageQueryStub.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageQueryStub.java Tue Jul 25 15:23:01 2006
@@ -0,0 +1,156 @@
+/**
+ * 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 java.util.List;
+
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.server.registry.ProvidedService;
+import org.apache.lucene.gdata.storage.StorageException;
+import org.apache.lucene.search.Searcher;
+
+import com.google.gdata.data.BaseEntry;
+import com.google.gdata.data.BaseFeed;
+import com.google.gdata.util.ParseException;
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+public class StorageQueryStub extends StorageQuery {
+
+ public boolean booleanReturn = true;
+
+ /**
+ * @param buffer
+ * @param searcher
+ */
+ public StorageQueryStub(StorageBuffer buffer, Searcher searcher) {
+ super(buffer, searcher);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageQuery#checkEntryVersion(java.lang.String, java.lang.String, int)
+ */
+ @Override
+ protected boolean checkEntryVersion(String id, String feedId, int version) throws IOException {
+
+ return booleanReturn;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageQuery#close()
+ */
+ @Override
+ public void close() throws IOException {
+
+ super.close();
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageQuery#entryQuery(java.util.List, java.lang.String, org.apache.lucene.gdata.server.registry.ProvidedService)
+ */
+ @Override
+ public List<BaseEntry> entryQuery(List<String> entryIds, String feedId, ProvidedService config) throws IOException, ParseException {
+
+ return null;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageQuery#getAccountNameForFeedId(java.lang.String)
+ */
+ @Override
+ public String getAccountNameForFeedId(String feedId) throws IOException {
+
+ return null;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageQuery#getEntryLastModified(java.lang.String, java.lang.String)
+ */
+ @Override
+ protected long getEntryLastModified(String entryId, String feedId) throws IOException, StorageException {
+
+ return System.currentTimeMillis();
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageQuery#getFeedLastModified(java.lang.String)
+ */
+ @Override
+ protected long getFeedLastModified(String feedId) throws IOException {
+
+ return System.currentTimeMillis();
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageQuery#getLatestFeedQuery(java.lang.String, int, int, org.apache.lucene.gdata.server.registry.ProvidedService)
+ */
+ @Override
+ public BaseFeed getLatestFeedQuery(String feedId, int resultCount, int startIndex, ProvidedService config) throws IOException, ParseException {
+
+ return null;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageQuery#getService(java.lang.String)
+ */
+ @Override
+ public String getService(String feedID) throws IOException {
+
+ return null;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageQuery#getUser(java.lang.String)
+ */
+ @Override
+ public GDataAccount getUser(String username) throws IOException {
+
+ return null;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageQuery#isEntryStored(java.lang.String, java.lang.String)
+ */
+ @Override
+ protected boolean isEntryStored(String entryId, String feedId) throws IOException {
+
+ return booleanReturn;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageQuery#isFeedStored(java.lang.String)
+ */
+ @Override
+ public boolean isFeedStored(String feedId) throws IOException {
+
+ return booleanReturn;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageQuery#singleEntryQuery(java.lang.String, java.lang.String, org.apache.lucene.gdata.server.registry.ProvidedService)
+ */
+ @Override
+ public BaseEntry singleEntryQuery(String entryId, String feedId, ProvidedService config) throws IOException, ParseException {
+
+ return null;
+ }
+
+}
Propchange: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageQueryStub.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageQueryStub.java
------------------------------------------------------------------------------
svn:executable = *