cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1079800 - in /cxf/trunk: rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/ rt/management-web/src/test/java/org/apache/cxf/management/web/loggi...
Date Wed, 09 Mar 2011 13:49:46 GMT
Author: sergeyb
Date: Wed Mar  9 13:49:45 2011
New Revision: 1079800

URL: http://svn.apache.org/viewvc?rev=1079800&view=rev
Log:
[CXF-3370] Adding tests for quering readonly storages

Added:
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/log.txt
  (with props)
Modified:
    cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java
    cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadableLogStorage.java
    cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
    cxf/trunk/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorageTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml

Modified: cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java?rev=1079800&r1=1079799&r2=1079800&view=diff
==============================================================================
--- cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java
(original)
+++ cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java
Wed Mar  9 13:49:45 2011
@@ -30,7 +30,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -50,8 +49,9 @@ public class ReadOnlyFileStorage impleme
     public static final String DATE_ONLY_FORMAT = "yyyy-MM-dd";
         
     private static final String LINE_SEP = System.getProperty("line.separator"); 
+    private static final String DEFAULT_COLUMN_SEP = "|";
     
-    private String columnSep;
+    private String columnSep = DEFAULT_COLUMN_SEP;
     private int numberOfColumns;
     private boolean startsFromSeparator;
     private boolean endsWithSeparator;
@@ -65,11 +65,9 @@ public class ReadOnlyFileStorage impleme
     private Comparator<String> fileNameComparator;
     
     private Map<Integer, String> columnsMap;
-    private List<FileInfo> logFiles 
-        = Collections.synchronizedList(new LinkedList<FileInfo>());  
+    private List<FileInfo> logFiles = new LinkedList<FileInfo>();  
     private Map<String, String> levelsMap;
-    private ConcurrentHashMap<Integer, PageInfo> pagesMap
-        = new ConcurrentHashMap<Integer, PageInfo>();
+    private Map<Integer, PageInfo> pagesMap = new HashMap<Integer, PageInfo>();
     
     /**
      * {@inheritDoc}
@@ -81,16 +79,22 @@ public class ReadOnlyFileStorage impleme
     /**
      * {@inheritDoc}
      */
-    public void load(List<LogRecord> list, 
+    // Synchronization can not be avoided at the moment as
+    // the file position is continuously changed.
+    // Realistically, the log files will probably be viewed
+    // by the admin so it's not a problem. However the memory mapping can
+    // help in making it more flexible
+    public synchronized int load(List<LogRecord> list, 
                      SearchCondition<LogRecord> condition, 
                      int pageNumber,
                      int pageSize) {
         FileInfo logFileInfo = getLogFileInfo(pageNumber);
         if (logFileInfo == null) {
-            return;
+            return pageNumber;
         }
         
-        int count = 0;
+        int recordCount = 0;
+        int currentIndex = 0;
         while (true) {
             LogRecord record = readRecord(logFileInfo);
             if (record == null) {
@@ -98,17 +102,23 @@ public class ReadOnlyFileStorage impleme
                 if (logFileInfo != null) {
                     continue;
                 } else {
-                    return;
+                    return pageNumber;
                 }
             }
             if (condition == null || condition.isMet(record)) {
                 list.add(record);
-                if (++count == pageSize) {
+                if (++recordCount == pageSize) {
+                    saveNextPagePosition(pageNumber + 1, logFileInfo);
                     break;
                 }
             }
+            if (++currentIndex == pageSize) {
+                pageNumber++;
+                recordCount = 0;
+                currentIndex = 0;
+            }
         }
-        savePagePosition(pageNumber, logFileInfo);
+        return pageNumber;
     }
 
     /**
@@ -120,7 +130,7 @@ public class ReadOnlyFileStorage impleme
             FileInfo fileInfo = logFiles.get(i);
             if (fileInfo == logFileInfo) {
                 if (i + 1 < logFiles.size()) {    
-                    return logFiles.get(i + 1); 
+                    return setFilePosition(logFiles.get(i + 1), logFiles.get(i + 1).getStartPosition());
                 } else {
                     break;
                 }
@@ -132,27 +142,29 @@ public class ReadOnlyFileStorage impleme
         return null;
     }
 
+    private FileInfo setFilePosition(FileInfo fileInfo, long pos) {
+        try {
+            fileInfo.getFile().seek(pos);
+            return fileInfo;
+        } catch (IOException ex) {
+            System.err.println("Problem setting a page position in " + fileInfo.getFileName());
+            return null;
+        }
+    }
+    
     /**
      * Gets the file corresponding to the current page.
      */
     private FileInfo getLogFileInfo(int pageNumber) {
         PageInfo pageInfo = pagesMap.get(pageNumber);
         if (pageInfo != null) {
-            FileInfo fileInfo = pageInfo.getFileInfo();
-            try {
-                fileInfo.getFile().seek(pageInfo.getPosition());
-            } catch (IOException ex) {
-                System.err.println("Problem setting a page position in " + fileInfo.getFileName());
-                return null;
-            }
-            return pageInfo.getFileInfo();
+            return setFilePosition(pageInfo.getFileInfo(), pageInfo.getPosition());
         }
         int oldSize = logFiles.size();
         if (logDirectory != null 
             && scanLogDirectory()) {
             FileInfo fileInfo = logFiles.get(oldSize);
-            // savePagePosition increases the number by 1
-            savePagePosition(pageNumber - 1, fileInfo);
+            saveNextPagePosition(pageNumber, fileInfo);
             return fileInfo;
         }
         return null;
@@ -161,15 +173,15 @@ public class ReadOnlyFileStorage impleme
     /**
      * Save the position of the next page 
      */
-    private void savePagePosition(int pageNumber, FileInfo fileInfo) {
+    private void saveNextPagePosition(int pageNumber, FileInfo fileInfo) {
         try {
             long pos = fileInfo.getFile().getFilePointer();
             if (pos < fileInfo.getFile().length()) {
-                pagesMap.put(pageNumber + 1, new PageInfo(fileInfo, pos));
+                pagesMap.put(pageNumber, new PageInfo(fileInfo, pos));
             } else {
                 FileInfo nextFileInfo = getNextLogFileInfo(fileInfo, false);
                 if (nextFileInfo != null) {
-                    pagesMap.put(pageNumber + 1, 
+                    pagesMap.put(pageNumber, 
                                  new PageInfo(nextFileInfo, nextFileInfo.getFile().getFilePointer()));
                 }
             }
@@ -341,22 +353,33 @@ public class ReadOnlyFileStorage impleme
         String fileModifiedDate = null;
         if (useFileModifiedDate) {
             if (fileNameDatePattern != null) {
-                Matcher m = fileNameDatePattern.matcher(file.getName());
-                if (m.matches() && m.groupCount() > 0) {
-                    fileModifiedDate = m.group(1);
-                }
+                fileModifiedDate = getDateFromFileName(file.getName());
             }
             if (fileModifiedDate == null) {
                 Date fileDate = new Date(file.lastModified());
                 fileModifiedDate = getLogDateFormat().format(fileDate);
             }
         }
-        
-        FileInfo fileInfo = new FileInfo(logFile, file.getName(), fileModifiedDate);
-        skipIgnorableRecords(fileInfo, logFiles.size() == 0);
+        skipIgnorableRecords(logFile);
+        FileInfo fileInfo = new FileInfo(logFile, 
+                                         file.getName(), 
+                                         fileModifiedDate,
+                                         logFile.getFilePointer());
+        if (logFiles.size() == 0) {
+            pagesMap.put(1, new PageInfo(fileInfo, fileInfo.getStartPosition()));
+        }
         logFiles.add(fileInfo);
     }
     
+    private String getDateFromFileName(String name) {
+        Matcher m = fileNameDatePattern.matcher(name);
+        if (m.matches() && m.groupCount() > 0) {
+            return m.group(1);
+        } else {
+            return null;
+        }
+    }
+    
     private SimpleDateFormat getLogDateFormat() {
         String format = fileNameDateFormat == null ? DATE_ONLY_FORMAT : fileNameDateFormat;
         return new SimpleDateFormat(format);
@@ -367,8 +390,12 @@ public class ReadOnlyFileStorage impleme
         int indexClose = location.indexOf("}");
         String realPath = null;
         if (indexOpen == 0 && indexClose != -1) {
-            realPath = location.substring(1, indexClose)
-                       + location.substring(indexClose + 1);
+            String property = location.substring(1, indexClose);
+            String resolvedPath = System.getProperty(property);
+            if (resolvedPath == null) {
+                throw new IllegalArgumentException("System property " + property + " can
not be resolved");
+            }
+            realPath = resolvedPath + location.substring(indexClose + 1);
             
         } else {
             realPath = location;
@@ -394,16 +421,16 @@ public class ReadOnlyFileStorage impleme
     /**
      * Skip the records at the top of the file which have no column separators 
      */
-    private void skipIgnorableRecords(FileInfo fInfo, boolean first) throws IOException {
-        long nextPos = fInfo.getFile().getFilePointer();
-        String line = fInfo.getFile().readLine();
+    private void skipIgnorableRecords(RandomAccessFile file) throws IOException {
+        long nextPos = file.getFilePointer();
+        if (nextPos == file.length()) {
+            return;
+        }
+        String line = file.readLine();
         if (line.contains(columnSep)) {
-            fInfo.getFile().seek(nextPos);
-            if (first) {
-                pagesMap.put(1, new PageInfo(fInfo, nextPos));
-            }
+            file.seek(nextPos);
         } else {
-            skipIgnorableRecords(fInfo, first);
+            skipIgnorableRecords(file);
         }
         
     }
@@ -467,7 +494,9 @@ public class ReadOnlyFileStorage impleme
     private boolean scanLogDirectory() {
         int oldSize = logFiles.size();
         for (File file : logDirectory.listFiles()) {
-            if (file.isDirectory() || file.isHidden()) {
+            if (file.isDirectory() || file.isHidden()
+                || fileNameDatePattern != null 
+                   && getDateFromFileName(file.getName()) == null) {
                 continue;
             }
             
@@ -531,11 +560,13 @@ public class ReadOnlyFileStorage impleme
         private RandomAccessFile file;
         private String fileModified;
         private String fileName;
+        private long startPosition;
         
-        public FileInfo(RandomAccessFile file, String fileName, String fileModified) {
+        public FileInfo(RandomAccessFile file, String fileName, String fileModified, long
startPos) {
             this.file = file;
             this.fileModified = fileModified;
             this.fileName = fileName;
+            this.startPosition = startPos;
         }
         
         public RandomAccessFile getFile() {
@@ -547,6 +578,9 @@ public class ReadOnlyFileStorage impleme
         public String getFileName() {
             return fileName;
         }
+        public long getStartPosition() {
+            return startPosition;
+        }
     }
  
     protected class FileInfoComparator implements Comparator<FileInfo> {

Modified: cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadableLogStorage.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadableLogStorage.java?rev=1079800&r1=1079799&r2=1079800&view=diff
==============================================================================
--- cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadableLogStorage.java
(original)
+++ cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadableLogStorage.java
Wed Mar  9 13:49:45 2011
@@ -35,16 +35,19 @@ public interface ReadableLogStorage {
      * @param condition the condition loaded records must meet, can be null 
      * @param pageNumber the initial page to have records loaded from
      * @param int pageSize the max number of records to load from the storage
+     * 
+     * @return the current page number; it may be different from the starting page if
+     *         certain records within the given page range did not match the search condition.
      */
-    void load(List<LogRecord> list, 
-              SearchCondition<LogRecord> condition,
-              int pageNumber, 
-              int pageSize);
+    int load(List<LogRecord> list, 
+             SearchCondition<LogRecord> condition,
+             int pageNumber, 
+             int pageSize);
     
     
     /**
      * Get the size of storage (in records)
-     * @param the size, -1 if not known, for ex, when reading from an open file containing
log entries
+     * @return the size, -1 if not known, for ex, when reading from an open file containing
log entries
      */
     int getSize();
     

Modified: cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java?rev=1079800&r1=1079799&r2=1079800&view=diff
==============================================================================
--- cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
(original)
+++ cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
Wed Mar  9 13:49:45 2011
@@ -36,7 +36,6 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 
 import org.apache.abdera.model.Entry;
@@ -64,7 +63,6 @@ public class AtomPullServer extends Abst
     private ReadableLogStorage storage;
     private int pageSize = 20;
     private int maxInMemorySize = 1000;
-    private boolean useArchivedFeeds;
     private volatile int recordsSize;
     private volatile boolean alreadyClosed;
     private SearchCondition<LogRecord> readableStorageCondition;
@@ -114,7 +112,7 @@ public class AtomPullServer extends Abst
                 r.setLevel(LogLevel.valueOf(l.getLevel()));
                 list.add(new SearchConditionImpl(r));
             }
-            readableStorageCondition = new OrSearchCondition<LogRecord>(list);
+            readableStorageCondition = list.size() == 0 ? null : new OrSearchCondition<LogRecord>(list);
         }
         initBusProperty();
     }
@@ -237,66 +235,32 @@ public class AtomPullServer extends Abst
     
     
     protected int fillSubList(List<LogRecord> list, int page, SearchCondition<LogRecord>
theSearch) {
+        int oldListSize = list.size();
         
-        if (recordsSize == -1) {
-            // let the external storage load the records it knows about
-            storage.load(list, theSearch, page == 1 ? 0 : (page - 1) * pageSize, pageSize);
-            return page;
+        if (storage != null) {
+            page = storage.load(list, theSearch, page, pageSize);
         }
         
-        if (recordsSize == 0) {
-            return 1;
+        if (recordsSize == -1 || recordsSize == 0 || list.size() == pageSize) {
+            return page;
         }
         
-        int fromIndex = 0;
-        int toIndex = 0;
-        // see http://tools.ietf.org/html/draft-nottingham-atompub-feed-history-07
-        if (!useArchivedFeeds) {
-            fromIndex = page == 1 ? 0 : (page - 1) * pageSize;
-            if (fromIndex > recordsSize) {
-                // this should not happen really
-                page = 1;
-                fromIndex = 0;
-            }
-            toIndex = page == 1 ? pageSize : fromIndex + pageSize;
-            if (toIndex > recordsSize) {
-                toIndex = recordsSize;
-            }
-        } else {
-            fromIndex = recordsSize - pageSize * page;
-            if (fromIndex < 0) {
-                fromIndex = 0;
-            }
-            toIndex = pageSize < recordsSize ? recordsSize : pageSize;
-        }
-
-        // if we have the storage then try to load from it
-        boolean loaded = false;
-        if (storage != null) {
-            if (fromIndex < storage.getSize()) {
-                int storageSize = storage.getSize();
-                int maxQuantityToLoad = toIndex > storageSize ? toIndex - storageSize
: toIndex - fromIndex;
-                storage.load(list, theSearch, fromIndex, maxQuantityToLoad);
-                loaded = true;
-                
-                int totalQuantity = toIndex - fromIndex;
-                if (list.size() < totalQuantity) {
-                    int remaining = totalQuantity - list.size();
-                    if (remaining > records.size()) {
-                        remaining = records.size();
-                    }
-                    fromIndex = 0;
-                    toIndex = remaining;
-                    loaded = false;
-                }
-            } else {
-                fromIndex -= storage.getSize();
-                toIndex -= storage.getSize();
-            }
-        } 
-        if (!loaded) {
-            list.addAll(filterRecords(records.subList(fromIndex, toIndex), theSearch));
-        }
+        int fromIndex = page == 1 ? list.size() 
+                                  : (page - 1) * pageSize + list.size();
+        if (fromIndex > recordsSize) {
+            // this should not happen really
+            page = 1;
+            fromIndex = 0;
+        }
+        int toIndex = page * pageSize;
+        if (toIndex > recordsSize) {
+            toIndex = recordsSize;
+        }
+        int offset = storage != null ? pageSize - (list.size() - oldListSize) : 0;
+        fromIndex -= offset;
+        toIndex -= offset;
+        list.addAll(filterRecords(records.subList(fromIndex, toIndex), theSearch));
+        
         
         if (theSearch != null && list.size() < pageSize && page * pageSize
< recordsSize) {
             return fillSubList(list, page + 1, theSearch);    
@@ -332,38 +296,26 @@ public class AtomPullServer extends Abst
         
         String uri = context.getUriInfo().getBaseUriBuilder().path("logs").build().toString();
         feed.addLink(uri + "/alternate/" + page, "alternate");
-        if (!useArchivedFeeds) {
-            if (recordsSize != -1) {
-                if (page > 2) {
-                    feed.addLink(createLinkUri(uri, searchExpression), "first");
-                }
-                
-                if (searchExpression == null && lastPage * pageSize < recordsSize
-                    || searchExpression != null && feedSize == pageSize) {
-                    feed.addLink(createLinkUri(uri + "/" + (lastPage + 1), searchExpression),
"next");
-                }
-                
-                if (searchExpression == null && page * (pageSize + 1) < recordsSize)
{
-                    feed.addLink(uri + "/" + (recordsSize / pageSize + 1), "last");
-                }
-            } else if (feedSize == pageSize) {
-                feed.addLink(createLinkUri(uri + "/" + (page + 1), searchExpression), "next");
+        if (recordsSize != -1) {
+            if (page > 2) {
+                feed.addLink(createLinkUri(uri, searchExpression), "first");
             }
-            if (searchExpression == null && page > 1) {
-                uri = page > 2 ? uri + "/" + (page - 1) : uri;
-                feed.addLink(createLinkUri(uri, searchExpression), "previous");
+            
+            if (searchExpression == null && lastPage * pageSize < recordsSize
+                || searchExpression != null && feedSize == pageSize) {
+                feed.addLink(createLinkUri(uri + "/" + (lastPage + 1), searchExpression),
"next");
             }
-        } else {
-            throw new WebApplicationException(Response.serverError()
-                                              .entity("Archived feeds are not supported yet")
-                                              .build());
-            // feed.addLink(self, "current");
-            // TODO : add prev-archive and next-archive; next-archive should not be set if
it will point to
-            // current
-            // and xmlns:fh="http://purl.org/syndication/history/1.0":archive extension but
only if
-            // it is not current
+            
+            if (searchExpression == null && page * (pageSize + 1) < recordsSize)
{
+                feed.addLink(uri + "/" + (recordsSize / pageSize + 1), "last");
+            }
+        } else if (feedSize == pageSize) {
+            feed.addLink(createLinkUri(uri + "/" + (lastPage + 1), searchExpression), "next");
+        }
+        if (page > 1) {
+            uri = page > 2 ? uri + "/" + (page - 1) : uri;
+            feed.addLink(createLinkUri(uri, searchExpression), "previous");
         }
-        
     }
     
     private String createLinkUri(String uri, String search) {

Modified: cxf/trunk/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorageTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorageTest.java?rev=1079800&r1=1079799&r2=1079800&view=diff
==============================================================================
--- cxf/trunk/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorageTest.java
(original)
+++ cxf/trunk/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorageTest.java
Wed Mar  9 13:49:45 2011
@@ -23,6 +23,10 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.cxf.jaxrs.ext.search.ConditionType;
+import org.apache.cxf.jaxrs.ext.search.PrimitiveSearchCondition;
+import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -80,6 +84,7 @@ public class ReadOnlyFileStorageTest ext
         assertTrue(lastRecord.getMessage().contains("Pax Web available at"));
     }
     
+        
     @Test
     public void testReadRecordsWithMultiLines() throws Exception {
         
@@ -113,6 +118,7 @@ public class ReadOnlyFileStorageTest ext
         readPage(2, 10, 10);
         readPage(3, 10, 10);
         List<LogRecord> recordsPage4 = readPage(4, 10, 10);
+        readPage(4, 10, 10);
         readPage(5, 10, 10);
         List<LogRecord> recordsLastPage1 = readPage(6, 10, 2);
         
@@ -131,6 +137,23 @@ public class ReadOnlyFileStorageTest ext
     }
     
     @Test
+    public void testReadRecordsWithMultipleFilesAndSearch() throws Exception {
+        
+        List<String> locations = new ArrayList<String>();
+        locations.add(getClass().getResource("logs/2011-01-22-karaf.log").toURI().getPath());
+        locations.add(getClass().getResource("logs/2011-01-23-karaf.log").toURI().getPath());
+        storage.setLogLocations(locations);
+        SearchCondition<LogRecord> sc = 
+            new PrimitiveSearchCondition<LogRecord>("message",
+                "*FeaturesServiceImpl.java:323*",
+                ConditionType.EQUALS,
+                new LogRecord()); 
+        List<LogRecord> recordsFirstPage1 = readPage(1, sc, 2, 1);
+        List<LogRecord> recordsFirstPage2 = readPage(1, sc, 2, 1);
+        compareRecords(recordsFirstPage1, recordsFirstPage2);
+    }
+    
+    @Test
     public void testReadRecordsWithMultipleFiles2() throws Exception {
         
         List<String> locations = new ArrayList<String>();
@@ -195,8 +218,14 @@ public class ReadOnlyFileStorageTest ext
     }
     
     private List<LogRecord> readPage(int page, int pageSize, int expected) {
+        return readPage(page, null, pageSize, expected);
+        
+    }
+    
+    private List<LogRecord> readPage(int page, SearchCondition<LogRecord> sc,
+                                     int pageSize, int expected) {
         List<LogRecord> records = new ArrayList<LogRecord>();
-        storage.load(records, null, page, pageSize);
+        storage.load(records, sc, page, pageSize);
         assertEquals(expected, records.size());
         return records;
         

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java?rev=1079800&r1=1079799&r2=1079800&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java
Wed Mar  9 13:49:45 2011
@@ -77,6 +77,9 @@ public class JAXRSLoggingAtomPullSpringT
         new Resource3();
         // must be 'in-process' to communicate with inner class in single JVM
         // and to spawn class SpringServer w/o using main() method
+        String resourceDir = 
+            JAXRSLoggingAtomPullSpringTest.class.getResource("resources").toURI().getPath();
+        System.setProperty("systemtests.jaxrs.logs.folder", resourceDir);
         launchServer(SpringServer.class, true);
         context = JAXBContext.newInstance(org.apache.cxf.management.web.logging.LogRecord.class);
     }
@@ -150,10 +153,11 @@ public class JAXRSLoggingAtomPullSpringT
         
         String address = "http://localhost:" + PORT + "/atom2/logs"
                          + "?_s=level==INFO,level==ERROR,level==WARN";
-        verifyPagesWithQuery(address, "next", 3, 2, "theNamedLogger");
-        verifyPagesWithQuery(address, "next", 3, 2, "theNamedLogger");    
+        verifyPagesWithQuery(address, "next", 3, 2, "Resource2", "theNamedLogger");
+        verifyPagesWithQuery(address, "next", 3, 2, "Resource2", "theNamedLogger");    
     }
     
+    
     @Test
     public void testPagedFeedWithReadWriteStorage() throws Exception {
         WebClient wc = WebClient.create("http://localhost:" + PORT + "/resource3/storage");
@@ -178,6 +182,84 @@ public class JAXRSLoggingAtomPullSpringT
                            "readOnlyStorageLogger", true);
     }
     
+    @Test
+    public void testPagedFeedWithReadonlyStorageAngQuery() throws Exception {
+        checkInfoLevelOnly();
+        checkDebugLevelOnly();
+        checkInfoLevelOnly();
+        checkDebugLevelOnly();
+        checkInfoOrDebugLevel();
+    }
+    
+    private void checkInfoLevelOnly() throws Exception {
+        String address = "http://localhost:" + PORT + "/atom5/logs"
+            + "?_s=level==INFO";
+        List<Entry> entries = new ArrayList<Entry>();
+        String href1 = fillPagedEntries(entries, address, 1, "next", true);
+        resetCounters();
+        for (Entry e : entries) {
+            updateCounters(readLogRecord(e.getContent()), "", "");
+        }
+        assertEquals(0, errorLevels);
+        assertEquals(1, infoLevels);
+        assertEquals(0, debugLevels);
+        assertEquals(0, traceLevels);
+        assertEquals(0, warningLevels);
+        
+        entries.clear();
+        fillPagedEntries(entries, href1, 0, "next", false);
+    }
+    
+    private void checkInfoOrDebugLevel() throws Exception {
+        String address = "http://localhost:" + PORT + "/atom5/logs"
+            + "?_s=level==INFO,level==DEBUG";
+        List<Entry> entries = new ArrayList<Entry>();
+        String href1 = fillPagedEntries(entries, address, 1, "next", true);
+        resetCounters();
+        for (Entry e : entries) {
+            updateCounters(readLogRecord(e.getContent()), "", "");
+        }
+        assertEquals(0, errorLevels);
+        assertEquals(1, infoLevels);
+        assertEquals(0, debugLevels);
+        assertEquals(0, traceLevels);
+        assertEquals(0, warningLevels);
+        
+        entries.clear();
+        String href2 = fillPagedEntries(entries, href1, 1, "next", true);
+        resetCounters();
+        for (Entry e : entries) {
+            updateCounters(readLogRecord(e.getContent()), "", "");
+        }
+        assertEquals(0, errorLevels);
+        assertEquals(0, infoLevels);
+        assertEquals(1, debugLevels);
+        assertEquals(0, traceLevels);
+        assertEquals(0, warningLevels);
+        
+        entries.clear();
+        fillPagedEntries(entries, href2, 0, "next", false);
+    }
+    
+    private void checkDebugLevelOnly() throws Exception {
+        String address = "http://localhost:" + PORT + "/atom5/logs"
+            + "?_s=level==DEBUG";
+        List<Entry> entries = new ArrayList<Entry>();
+        String href1 = fillPagedEntries(entries, address, 1, "next", true);
+        resetCounters();
+        for (Entry e : entries) {
+            updateCounters(readLogRecord(e.getContent()), "", "");
+        }
+        assertEquals(0, errorLevels);
+        assertEquals(0, infoLevels);
+        assertEquals(1, debugLevels);
+        assertEquals(0, traceLevels);
+        assertEquals(0, warningLevels);
+        
+        entries.clear();
+        fillPagedEntries(entries, href1, 0, "next", false);
+    }
+    
     private void verifyStoragePages(String startAddress, String rel, 
                                     String resourceName, String nLogger,
                                     boolean readOnly) 
@@ -219,7 +301,7 @@ public class JAXRSLoggingAtomPullSpringT
     }
     
     private void verifyPagesWithQuery(String startAddress, String rel, 
-                             int firstValue, int lastValue, String nLogger) 
+                             int firstValue, int lastValue, String resourceName, String nLogger)

         throws Exception {
         List<Entry> entries = new ArrayList<Entry>();
         String hrefRel = fillPagedEntries(entries, startAddress, 
@@ -369,16 +451,17 @@ public class JAXRSLoggingAtomPullSpringT
             return -1;
         }
 
-        public void load(List<org.apache.cxf.management.web.logging.LogRecord> list,

-                         SearchCondition<org.apache.cxf.management.web.logging.LogRecord>
condition, 
-                         int loadFrom, 
-                         int maxNumberOfRecords) {
-            int limit = loadFrom + maxNumberOfRecords;
-            for (int i = loadFrom; i < limit; i++) {
+        public int load(List<org.apache.cxf.management.web.logging.LogRecord> list,

+                        SearchCondition<org.apache.cxf.management.web.logging.LogRecord>
condition, 
+                        int pageNumber, 
+                        int pageSize) {
+            int loadFrom = pageNumber == 1 ? 0 : pageSize * (pageNumber - 1);
+            for (int i = loadFrom; i < loadFrom + pageSize; i++) {
                 if (condition.isMet(records.get(i))) {
                     list.add(records.get(i));
                 }
             }
+            return pageNumber;
         }
         
     }
@@ -388,10 +471,15 @@ public class JAXRSLoggingAtomPullSpringT
         private static List<org.apache.cxf.management.web.logging.LogRecord> records
= 
             new LinkedList<org.apache.cxf.management.web.logging.LogRecord>();
 
-        public void load(List<org.apache.cxf.management.web.logging.LogRecord> list,
+        public int load(List<org.apache.cxf.management.web.logging.LogRecord> list,
                          SearchCondition<org.apache.cxf.management.web.logging.LogRecord>
sc,
-                         int from, int quantity) {
-            list.addAll(records.subList(from, from + quantity));
+                         int pageNumber, int pageSize) {
+            
+            int loadFrom = pageNumber == 1 ? 0 : pageSize * (pageNumber - 1);
+            if (loadFrom + pageSize <= records.size()) {
+                list.addAll(records.subList(loadFrom, loadFrom + pageSize));
+            }
+            return pageNumber;
         }
 
         public void save(List<org.apache.cxf.management.web.logging.LogRecord> list)
{

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/log.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/log.txt?rev=1079800&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/log.txt
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/log.txt
Wed Mar  9 13:49:45 2011
@@ -0,0 +1,2 @@
+INFO | Info message
+DEBUG | Debug Message

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/log.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/log.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml?rev=1079800&r1=1079799&r2=1079800&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml Wed
Mar  9 13:49:45 2011
@@ -85,8 +85,27 @@ http://www.springframework.org/schema/ut
 		</property>	
 	</bean>      
 
+    <bean id = "atomPullServer5" class="org.apache.cxf.management.web.logging.atom.AtomPullServer"

+	      init-method="init">
+		  <property name="pageSize" value="1"/>
+		  <property name="storage">
+			<ref bean="storage3" />
+		</property>	
+	</bean>
+
    	<bean id="storage" class="org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$Storage"/>

-   	<bean id="storage2" class="org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$ExternalStorage"/>

+   	<bean id="storage2" class="org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$ExternalStorage"/>
+   	<bean id="storage3" class="org.apache.cxf.management.web.logging.ReadOnlyFileStorage">
+   	    <property name="logLocation" value="{systemtests.jaxrs.logs.folder}/log.txt"/>
+   	    <property name="numberOfColumns" value="2"/>
+   	    <property name="columnsMap">
+   	       <map>
+   	         <entry key="1" value="level"/>
+   	         <entry key="2" value="message"/>
+   	       </map>
+   	    </property>
+   	</bean>
+   	 
 
 	<bean id="feed" class="org.apache.cxf.jaxrs.provider.AtomFeedProvider">
 	    <property name="formattedOutput" value="true"/>
@@ -159,6 +178,14 @@ http://www.springframework.org/schema/ut
 		</jaxrs:providers>
 	</jaxrs:server>
     
+    <jaxrs:server id="atomServer5" address="/atom5">
+		<jaxrs:serviceBeans>
+			<ref bean="atomPullServer5"/>
+		</jaxrs:serviceBeans>
+		<jaxrs:providers>
+			<ref bean="feed" />
+		</jaxrs:providers>
+	</jaxrs:server>
     
     <jaxrs:server id="atomReset" address="/reset">
 		<jaxrs:serviceBeans>



Mime
View raw message