weaver 2004/05/11 11:20:27
Modified: components/file-cache/src/test/org/apache/jetspeed/cache/file
Tag: NANOCONTAINER_DEPLOYER FileCopy.java
TestFileCache.java
components/file-cache/src/test Tag: NANOCONTAINER_DEPLOYER
Log4j.properties
Added: components/file-cache/src/java/org/apache/jetspeed/cache/file/impl
Tag: NANOCONTAINER_DEPLOYER BaseFileCache.groovy
Log:
the great component migration
Revision Changes Path
No revision
No revision
1.1.2.2 +111 -111
jakarta-jetspeed-2/components/file-cache/src/test/org/apache/jetspeed/cache/file/Attic/FileCopy.java
Index: FileCopy.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/components/file-cache/src/test/org/apache/jetspeed/cache/file/Attic/FileCopy.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- FileCopy.java 20 Apr 2004 19:41:19 -0000 1.1.2.1
+++ FileCopy.java 11 May 2004 18:20:27 -0000 1.1.2.2
@@ -1,112 +1,112 @@
-/*
- * Copyright 2000-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.jetspeed.cache.file;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.DataInputStream;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-
-/*
- * File Copy Utilities. Some utilities that java.io doesn't give us.
- *
- * copy() - copies one file source to another file destination.
- * copyFromURL)() - copies from a URL source to a file destination.
- *
- * NOTE: tried to be a good Commons-citizen and use io out of the sandbox
- * at the time it was dependent on an older version of commons-lang for a
predicate class bs bs
- *
- * @author David S. Taylor <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
- * @version $Id$
- */
-
-public class FileCopy
-{
- public static final int BUFFER_SIZE = 4096;
-
- /*
- * Copies one file source to another file destination.
- *
- * @param source The source file.
- * @param destination The destination file.
- * @throws IOException When an IO error occurs, this exception is thrown.
- */
- public static final void copy(String source, String destination)
- throws IOException
- {
- byte[] buffer = new byte[BUFFER_SIZE];
- BufferedInputStream input;
- BufferedOutputStream output;
-
- input = new BufferedInputStream(new FileInputStream(source));
- output = new BufferedOutputStream(new FileOutputStream(destination));
-
- copyStream(input, output, buffer);
-
- input.close();
- output.close();
- }
-
- /*
- * Copies from a URL source to a file destination.
- *
- * @param source The source URL.
- * @param destination The destination file.
- * @throws IOException When an IO error occurs, this exception is thrown.
- */
- public static final void copyFromURL(String source, String destination)
- throws IOException
- {
- byte[] buffer = new byte[BUFFER_SIZE];
- URL url = new URL(source);
- BufferedInputStream input;
- BufferedOutputStream output;
-
-
- input = new BufferedInputStream(new DataInputStream(url.openStream()));
- output = new BufferedOutputStream(new FileOutputStream(destination));
-
- copyStream(input, output, buffer);
-
- input.close();
- output.close();
- }
-
- /*
- * Generic copy from a input stream to an output stream.
- *
- * @param input The source input stream.
- * @param output The destination output stream.
- * @param buffer The user provided buffer.
- * @throws IOException When an IO error occurs, this exception is thrown.
- */
- public static final void copyStream(InputStream input,
- OutputStream output,
- byte[] buffer)
- throws IOException
- {
- int bytesRead;
-
- while((bytesRead = input.read(buffer)) != -1)
- output.write(buffer, 0, bytesRead);
- }
-
+/*
+ * Copyright 2000-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.jetspeed.cache.file;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.DataInputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+
+/*
+ * File Copy Utilities. Some utilities that java.io doesn't give us.
+ *
+ * copy() - copies one file source to another file destination.
+ * copyFromURL)() - copies from a URL source to a file destination.
+ *
+ * NOTE: tried to be a good Commons-citizen and use io out of the sandbox
+ * at the time it was dependent on an older version of commons-lang for a
predicate class bs bs
+ *
+ * @author David S. Taylor <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
+ * @version $Id$
+ */
+
+public class FileCopy
+{
+ public static final int BUFFER_SIZE = 4096;
+
+ /*
+ * Copies one file source to another file destination.
+ *
+ * @param source The source file.
+ * @param destination The destination file.
+ * @throws IOException When an IO error occurs, this exception is thrown.
+ */
+ public static final void copy(String source, String destination)
+ throws IOException
+ {
+ byte[] buffer = new byte[BUFFER_SIZE];
+ BufferedInputStream input;
+ BufferedOutputStream output;
+
+ input = new BufferedInputStream(new FileInputStream(source));
+ output = new BufferedOutputStream(new FileOutputStream(destination));
+
+ copyStream(input, output, buffer);
+
+ input.close();
+ output.close();
+ }
+
+ /*
+ * Copies from a URL source to a file destination.
+ *
+ * @param source The source URL.
+ * @param destination The destination file.
+ * @throws IOException When an IO error occurs, this exception is thrown.
+ */
+ public static final void copyFromURL(String source, String destination)
+ throws IOException
+ {
+ byte[] buffer = new byte[BUFFER_SIZE];
+ URL url = new URL(source);
+ BufferedInputStream input;
+ BufferedOutputStream output;
+
+
+ input = new BufferedInputStream(new DataInputStream(url.openStream()));
+ output = new BufferedOutputStream(new FileOutputStream(destination));
+
+ copyStream(input, output, buffer);
+
+ input.close();
+ output.close();
+ }
+
+ /*
+ * Generic copy from a input stream to an output stream.
+ *
+ * @param input The source input stream.
+ * @param output The destination output stream.
+ * @param buffer The user provided buffer.
+ * @throws IOException When an IO error occurs, this exception is thrown.
+ */
+ public static final void copyStream(InputStream input,
+ OutputStream output,
+ byte[] buffer)
+ throws IOException
+ {
+ int bytesRead;
+
+ while((bytesRead = input.read(buffer)) != -1)
+ output.write(buffer, 0, bytesRead);
+ }
+
}
1.1.2.4 +230 -229
jakarta-jetspeed-2/components/file-cache/src/test/org/apache/jetspeed/cache/file/Attic/TestFileCache.java
Index: TestFileCache.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/components/file-cache/src/test/org/apache/jetspeed/cache/file/Attic/TestFileCache.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- TestFileCache.java 23 Apr 2004 22:33:28 -0000 1.1.2.3
+++ TestFileCache.java 11 May 2004 18:20:27 -0000 1.1.2.4
@@ -1,229 +1,230 @@
-/*
- * Copyright 2000-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.jetspeed.cache.file;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.Date;
-import java.util.Iterator;
-
-import junit.framework.Test;
-
-import org.apache.commons.io.StreamUtils;
-import org.apache.commons.lang.exception.ExceptionUtils;
-import org.apache.jetspeed.cache.file.FileCache;
-import org.apache.jetspeed.components.AbstractComponentAwareTestCase;
-import org.apache.jetspeed.components.NanoDeployerBasedTestSuite;
-import org.picocontainer.MutablePicoContainer;
-import org.picocontainer.PicoContainer;
-
-/**
- * Unit test for FileCache
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
- * @version $Id$
- */
-
-public class TestFileCache extends AbstractComponentAwareTestCase implements
FileCacheEventListener
-{
- String refreshedEntry = null;
-
- /**
- * Defines the testcase name for JUnit.
- *
- * @param name the testcase's name.
- */
- public TestFileCache( String name )
- {
- super( name );
- }
-
-
- /**
- * Creates the test suite.
- *
- * @return a test suite (<code>TestSuite</code>) that includes all methods
- * starting with "test"
- */
- public static Test suite()
- {
- // ComponentAwareTestSuite suite = new
ComponentAwareTestSuite(TestFileCache.class);
- //
suite.setScript("org/apache/jetspeed/cache/file/filecache.container.groovy");
- return new NanoDeployerBasedTestSuite(TestFileCache.class);
- }
-
- private MutablePicoContainer container = null;
-
- private FileCache cache = null;
-
- private FileCache cacheViaParent;
-
- protected void setUp() throws Exception
- {
- super.setUp();
- container = (MutablePicoContainer) getContainer();
- cache = (FileCache) container.getComponentInstance(FileCache.class);
- PicoContainer parent = container.getParent();
- cacheViaParent = (FileCache) parent.getComponentInstance(FileCache.class);
- }
-
- public void testComponent()
- throws Exception
- {
- assertNotNull("container failed to load", container);
- assertNotNull("component failed to load", cache);
- assertNotNull("component failed to load via parent", cacheViaParent);
- }
-
- /**
- * Tests loading the cache
- * @throws Exception
- */
-
- public void testLoadCache() throws Exception
- {
- String templateFile =
getApplicationRoot()+"/test/testdata/psml/user/cachetest/default.psml";
- try
- {
- File file = new File(templateFile);
- assertTrue(file.exists());
-
- createTestFiles(templateFile);
-
- // create the Cache wake up after 10 seconds, cache size 20
- // FileCache cache = new FileCache(10, 20);
-
- // load the Cache
- File directory = new
File(getApplicationRoot()+"/test/testdata/psml/user/cachetest/");
- File[] files = directory.listFiles();
- for (int ix=0; ix < files.length; ix++)
- {
- if (files[ix].isDirectory() ||
files[ix].getName().equals(".cvsignore"))
- {
- continue;
- }
- String testData = readFile(files[ix]);
- cache.put(files[ix], testData);
- }
-
- assertTrue(cache.getSize() == 31);
-
- dumpCache(cache.getIterator());
-
- cache.addListener(this);
- // start the cache's scanner
- cache.startFileScanner();
-
- Thread.sleep(2000);
-
- assertTrue(cache.getSize() == 20);
-
- dumpCache(cache.getIterator());
-
- String stuff = (String) cache.getDocument(files[18].getCanonicalPath());
- assertNotNull(stuff);
-
- files[18].setLastModified(new Date().getTime());
-
-
- Thread.sleep(9000);
-
- assertNotNull(refreshedEntry);
- System.out.println("refreshed entry = " + refreshedEntry);
-
- cache.stopFileScanner();
-
- removeTestFiles();
- }
- catch (Exception e)
- {
- fail(ExceptionUtils.getStackTrace(e));
- }
-
- System.out.println("Completed loadCache Test OK ");
-
- }
-
- private void createTestFiles(String templateFile)
- throws java.io.IOException
- {
- for (int ix=1; ix < 31; ix++)
- {
- String testFile =
getApplicationRoot()+"/test/testdata/psml/user/cachetest/testFile-" + ix + ".psml";
- FileCopy.copy(templateFile, testFile);
- }
- }
-
- private void removeTestFiles()
- {
- for (int ix=1; ix < 31; ix++)
- {
- String testFile =
getApplicationRoot()+"/test/testdata/psml/user/cachetest/testFile-" + ix + ".psml";
- File file = new File(testFile);
- file.delete();
- }
- }
-
- private String readFile(File file)
- throws java.io.IOException, java.io.FileNotFoundException
- {
- BufferedInputStream input;
-
- input = new BufferedInputStream(new FileInputStream(file));
- String result = StreamUtils.streamAsString(input);
- input.close();
- return result;
- }
-
- /**
- * Refresh event, called when the entry is being refreshed from file system.
- *
- * @param entry the entry being refreshed.
- */
- public void refresh(FileCacheEntry entry)
- {
- System.out.println("entry is refreshing: " + entry.getFile().getName());
- this.refreshedEntry = entry.getFile().getName();
- }
-
- /**
- * Evict event, called when the entry is being evicted out of the cache
- *
- * @param entry the entry being refreshed.
- */
- public void evict(FileCacheEntry entry)
- {
- System.out.println("entry is evicting: " + entry.getFile().getName());
- }
-
- private void dumpCache(Iterator it)
- {
- for ( ; it.hasNext(); )
- {
- FileCacheEntry entry = (FileCacheEntry) it.next();
- System.out.println(entry.getFile().getName());
- }
- }
-
-}
-
-
-
-
-
-
+/*
+ * Copyright 2000-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.jetspeed.cache.file;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Date;
+import java.util.Iterator;
+
+import junit.framework.Test;
+
+import org.apache.commons.io.StreamUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.jetspeed.components.AbstractComponentAwareTestCase;
+import org.apache.jetspeed.components.ContainerDeployerTestSuite;
+import org.picocontainer.MutablePicoContainer;
+import org.picocontainer.PicoContainer;
+
+/**
+ * Unit test for FileCache
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
+ * @version $Id$
+ */
+
+public class TestFileCache extends AbstractComponentAwareTestCase implements
FileCacheEventListener
+{
+ String refreshedEntry = null;
+
+ /**
+ * Defines the testcase name for JUnit.
+ *
+ * @param name the testcase's name.
+ */
+ public TestFileCache( String name )
+ {
+ super( name );
+ }
+
+
+ /**
+ * Creates the test suite.
+ *
+ * @return a test suite (<code>TestSuite</code>) that includes all methods
+ * starting with "test"
+ */
+ public static Test suite()
+ {
+ // ComponentAwareTestSuite suite = new
ComponentAwareTestSuite(TestFileCache.class);
+ //
suite.setScript("org/apache/jetspeed/cache/file/filecache.container.groovy");
+ // return new NanoDeployerBasedTestSuite(TestFileCache.class);
+ return new ContainerDeployerTestSuite(TestFileCache.class);
+ }
+
+ private MutablePicoContainer container = null;
+
+ private FileCache cache = null;
+
+ private FileCache cacheViaParent;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ container = (MutablePicoContainer) getContainer();
+ cache = (FileCache) container.getComponentInstance(FileCache.class);
+// PicoContainer parent = container.getParent();
+// cacheViaParent = (FileCache) parent.getComponentInstance(FileCache.class);
+ }
+
+ public void testComponent()
+ throws Exception
+ {
+ assertNotNull("container failed to load", container);
+ assertNotNull("component failed to load", cache);
+
+ }
+
+ /**
+ * Tests loading the cache
+ * @throws Exception
+ */
+
+ public void testLoadCache() throws Exception
+ {
+
+ String templateFile =
getApplicationRoot()+"/test/testdata/psml/user/cachetest/default.psml";
+ try
+ {
+ File file = new File(templateFile);
+ assertTrue(file.exists());
+
+ createTestFiles(templateFile);
+
+ // create the Cache wake up after 10 seconds, cache size 20
+ // FileCache cache = new FileCache(10, 20);
+
+ // load the Cache
+ File directory = new
File(getApplicationRoot()+"/test/testdata/psml/user/cachetest/");
+ File[] files = directory.listFiles();
+ for (int ix=0; ix < files.length; ix++)
+ {
+ if (files[ix].isDirectory() ||
files[ix].getName().equals(".cvsignore"))
+ {
+ continue;
+ }
+ String testData = readFile(files[ix]);
+ cache.put(files[ix], testData);
+ }
+
+ assertTrue(cache.getSize() == 31);
+
+ dumpCache(cache.getIterator());
+
+ cache.addListener(this);
+ // start the cache's scanner
+ cache.startFileScanner();
+
+ Thread.sleep(2000);
+
+ assertTrue(cache.getSize() == 20);
+
+ dumpCache(cache.getIterator());
+
+ String stuff = (String) cache.getDocument(files[18].getCanonicalPath());
+ assertNotNull(stuff);
+
+ files[18].setLastModified(new Date().getTime());
+
+
+ Thread.sleep(9000);
+
+ assertNotNull(refreshedEntry);
+ System.out.println("refreshed entry = " + refreshedEntry);
+
+ cache.stopFileScanner();
+
+ removeTestFiles();
+ }
+ catch (Exception e)
+ {
+ fail(ExceptionUtils.getStackTrace(e));
+ }
+
+ System.out.println("Completed loadCache Test OK ");
+
+ }
+
+ private void createTestFiles(String templateFile)
+ throws java.io.IOException
+ {
+ for (int ix=1; ix < 31; ix++)
+ {
+ String testFile =
getApplicationRoot()+"/test/testdata/psml/user/cachetest/testFile-" + ix + ".psml";
+ FileCopy.copy(templateFile, testFile);
+ }
+ }
+
+ private void removeTestFiles()
+ {
+ for (int ix=1; ix < 31; ix++)
+ {
+ String testFile =
getApplicationRoot()+"/test/testdata/psml/user/cachetest/testFile-" + ix + ".psml";
+ File file = new File(testFile);
+ file.delete();
+ }
+ }
+
+ private String readFile(File file)
+ throws java.io.IOException, java.io.FileNotFoundException
+ {
+ BufferedInputStream input;
+
+ input = new BufferedInputStream(new FileInputStream(file));
+ String result = StreamUtils.streamAsString(input);
+ input.close();
+ return result;
+ }
+
+ /**
+ * Refresh event, called when the entry is being refreshed from file system.
+ *
+ * @param entry the entry being refreshed.
+ */
+ public void refresh(FileCacheEntry entry)
+ {
+ System.out.println("entry is refreshing: " + entry.getFile().getName());
+ this.refreshedEntry = entry.getFile().getName();
+ }
+
+ /**
+ * Evict event, called when the entry is being evicted out of the cache
+ *
+ * @param entry the entry being refreshed.
+ */
+ public void evict(FileCacheEntry entry)
+ {
+ System.out.println("entry is evicting: " + entry.getFile().getName());
+ }
+
+ private void dumpCache(Iterator it)
+ {
+ for ( ; it.hasNext(); )
+ {
+ FileCacheEntry entry = (FileCacheEntry) it.next();
+ System.out.println(entry.getFile().getName());
+ }
+ }
+
+}
+
+
+
+
+
+
No revision
No revision
1.1.2.2 +43 -43
jakarta-jetspeed-2/components/file-cache/src/test/Attic/Log4j.properties
Index: Log4j.properties
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/components/file-cache/src/test/Attic/Log4j.properties,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- Log4j.properties 22 Apr 2004 21:02:07 -0000 1.1.2.1
+++ Log4j.properties 11 May 2004 18:20:27 -0000 1.1.2.2
@@ -1,43 +1,43 @@
-# ------------------------------------------------------------------------
-#
-# Logging Configuration
-#
-# $Id$
-#
-# ------------------------------------------------------------------------
-
-#
-# If we don't know the logging facility, put it into the jetspeed.log
-#
-#
-log4j.rootLogger = INFO, console
-
-#
-# Jetspeed goes into Jetspeed Log
-#
-log4j.category.org.apache.jetspeed = DEBUG, console
-log4j.additivity.org.apache.jetspeed = false
-
-#
-# Velocity Logfile
-#
-log4j.category.velocity = INFO, console
-log4j.additivity.velocity = false
-
-#
-# OJB Logfile
-#
-log4j.category.org.apache.ojb= INFO, console
-log4j.additivity.org.apache.ojb= false
-
-
-
-
-#
-# Console
-#
-log4j.appender.console=org.apache.log4j.ConsoleAppender
-log4j.appender.console.layout=org.apache.log4j.PatternLayout
-
-# Pattern to output the caller's file name and line number.
-log4j.appender.console.layout.ConversionPattern=%5p: %m%n
+# ------------------------------------------------------------------------
+#
+# Logging Configuration
+#
+# $Id$
+#
+# ------------------------------------------------------------------------
+
+#
+# If we don't know the logging facility, put it into the jetspeed.log
+#
+#
+log4j.rootLogger = INFO, console
+
+#
+# Jetspeed goes into Jetspeed Log
+#
+log4j.category.org.apache.jetspeed = DEBUG, console
+log4j.additivity.org.apache.jetspeed = false
+
+#
+# Velocity Logfile
+#
+log4j.category.velocity = INFO, console
+log4j.additivity.velocity = false
+
+#
+# OJB Logfile
+#
+log4j.category.org.apache.ojb= INFO, console
+log4j.additivity.org.apache.ojb= false
+
+
+
+
+#
+# Console
+#
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+
+# Pattern to output the caller's file name and line number.
+log4j.appender.console.layout.ConversionPattern=%5p: %m%n
No revision
No revision
1.1.2.1 +37 -0
jakarta-jetspeed-2/components/file-cache/src/java/org/apache/jetspeed/cache/file/impl/Attic/BaseFileCache.groovy
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]