FileDocCategorySizeDatePackage
TestStorageBuffer.javaAPI DocApache Lucene 2.1.010938Wed Feb 14 10:46:02 GMT 2007org.apache.lucene.gdata.storage.lucenestorage

TestStorageBuffer

public class TestStorageBuffer extends TestCase
Copyright 2004 The Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Fields Summary
private static final String
FEEDID
private static final String
ENTRYID
private StorageBuffer
buffer
Constructors Summary
Methods Summary
public org.apache.lucene.gdata.data.ServerBaseEntrycreateServerBaseEntry(java.lang.String entryID, java.lang.String feedId)

        ServerBaseEntry e = new ServerBaseEntry();
        e.setId(entryID);
        e.setFeedId(feedId);
        e.setServiceConfig(new ProvidedServiceStub());
       return e;
    
protected voidsetUp()

         
        super.setUp();
        this.buffer = new StorageBuffer(10);
    
protected voidtearDown()

        this.buffer.close();
    
public voidtestAddDeleted()

        
        this.buffer.addDeleted(ENTRYID,FEEDID);
        assertNull(this.buffer.getSortedEntries(FEEDID));
        assertEquals(1,this.buffer.getExculdList().length);
        assertEquals(ENTRYID,this.buffer.getExculdList()[0]);
        
        this.buffer.addDeleted(ENTRYID,FEEDID);
        assertNull(this.buffer.getSortedEntries(FEEDID));
        assertEquals(1,this.buffer.getExculdList().length);
        assertEquals(ENTRYID,this.buffer.getExculdList()[0]);
        
        
    
public voidtestAddEntry()

        
        ServerBaseEntry e = createServerBaseEntry(ENTRYID,FEEDID);
        StorageEntryWrapper wrapper = new StorageEntryWrapper(e,StorageOperation.INSERT);
        this.buffer.addEntry(wrapper);
        assertEquals(1,this.buffer.getSortedEntries(FEEDID).size());
        this.buffer.addEntry(wrapper);
        assertEquals(1,this.buffer.getSortedEntries(FEEDID).size());
        
        e.setId("someotherID");
        e.setFeedId(FEEDID);
        e.setServiceConfig(new ProvidedServiceStub());
        wrapper = new StorageEntryWrapper(e,StorageOperation.INSERT);
        this.buffer.addEntry(wrapper);
        assertEquals(2,this.buffer.getSortedEntries(FEEDID).size());
        e.setId("someotherID");
        e.setFeedId("someOtherFeed");
        e.setServiceConfig(new ProvidedServiceStub());
        wrapper = new StorageEntryWrapper(e,StorageOperation.UPDATE);
        this.buffer.addEntry(wrapper);
        wrapper = new StorageEntryWrapper(e,StorageOperation.DELETE);
        e.setId("deleted and ingnored");
        e.setFeedId("someOtherFeed");
        e.setServiceConfig(new ProvidedServiceStub());
        this.buffer.addEntry(wrapper);
        assertEquals(2,this.buffer.getSortedEntries(FEEDID).size());
        assertEquals(1,this.buffer.getSortedEntries("someOtherFeed").size());
        assertEquals("Contains 2 different IDs",2,this.buffer.getExculdList().length);
        
    
public voidtestClose()

        ServerBaseEntry e = createServerBaseEntry(ENTRYID,FEEDID);
        StorageEntryWrapper wrapper = new StorageEntryWrapper(e,StorageOperation.INSERT);
        
        this.buffer.addEntry(wrapper);
        assertNotNull(this.buffer.getSortedEntries(FEEDID));
        assertNotNull(this.buffer.getEntry(ENTRYID,FEEDID));
        assertEquals(1,this.buffer.getExculdList().length);
        this.buffer.close();
        assertNull(this.buffer.getSortedEntries(FEEDID));
        assertNull(this.buffer.getEntry(ENTRYID,FEEDID));
        assertEquals(0,this.buffer.getExculdList().length);
        
        

    
public voidtestGetEntry()

        assertNull(this.buffer.getEntry(ENTRYID,FEEDID));
        ServerBaseEntry e = createServerBaseEntry(ENTRYID,FEEDID);
        StorageEntryWrapper wrapper = new StorageEntryWrapper(e,StorageOperation.INSERT);
        this.buffer.addEntry(wrapper);
        assertSame(wrapper,this.buffer.getEntry(ENTRYID,FEEDID));
        
        e = createServerBaseEntry("0",FEEDID);
        wrapper = new StorageEntryWrapper(e,StorageOperation.UPDATE);
        this.buffer.addEntry(wrapper);
        assertSame(wrapper,this.buffer.getEntry("0",FEEDID));
        
        
    
public voidtestGetExculdList()

        ServerBaseEntry e = createServerBaseEntry(ENTRYID,FEEDID);
        StorageEntryWrapper wrapper = new StorageEntryWrapper(e,StorageOperation.INSERT);
        this.buffer.addEntry(wrapper);
        this.buffer.addEntry(wrapper);
        assertEquals(1,this.buffer.getExculdList().length);
        assertEquals(wrapper.getEntryId(),this.buffer.getExculdList()[0]);
        
        wrapper = new StorageEntryWrapper(e,StorageOperation.UPDATE);
        this.buffer.addEntry(wrapper);
        assertEquals(1,this.buffer.getExculdList().length);
        assertEquals(wrapper.getEntryId(),this.buffer.getExculdList()[0]);
        this.buffer.addDeleted(ENTRYID,FEEDID);
        assertEquals(1,this.buffer.getExculdList().length);
        assertEquals(wrapper.getEntryId(),this.buffer.getExculdList()[0]);
        
         e = createServerBaseEntry("someOtherEntry","someOtherFeed");
        wrapper = new StorageEntryWrapper(e,StorageOperation.INSERT);
        this.buffer.addEntry(wrapper);
        this.buffer.addEntry(wrapper);
        assertEquals(2,this.buffer.getExculdList().length);
        
        
    
public voidtestGetFeedLastModified()

        ServerBaseEntry e = createServerBaseEntry(ENTRYID,FEEDID);
        e.setUpdated(new DateTime(System.currentTimeMillis()-200,0));
        StorageEntryWrapper wrapper = new StorageEntryWrapper(e,StorageOperation.INSERT);
        this.buffer.addEntry(wrapper);
        assertEquals(new Long(e.getUpdated().getValue()),this.buffer.getFeedLastModified(FEEDID));
        //test update
//      force timestamp
        e.setUpdated(new DateTime(System.currentTimeMillis()-180,0));
        wrapper = new StorageEntryWrapper(e,StorageOperation.UPDATE);
        this.buffer.addEntry(wrapper);
        Long firstAddTimestamp = new Long(e.getUpdated().getValue());
        assertEquals(firstAddTimestamp,this.buffer.getFeedLastModified(FEEDID));
//      force timestamp
        e.setUpdated(new DateTime(System.currentTimeMillis()-160,0));
        assertFalse("updated after add" ,e.getUpdated().equals(this.buffer.getFeedLastModified(FEEDID)));
        
        //insert for other feed
        String otherID = "someOtherFeedID";
        e.setFeedId(otherID);
//      force timestamp
        e.setUpdated(new DateTime(System.currentTimeMillis()-140,0));
        wrapper = new StorageEntryWrapper(e,StorageOperation.INSERT);
        this.buffer.addEntry(wrapper);
        assertEquals(new Long(e.getUpdated().getValue()),this.buffer.getFeedLastModified(otherID));
        assertEquals(firstAddTimestamp,this.buffer.getFeedLastModified(FEEDID));
        
        assertTrue(firstAddTimestamp.equals(this.buffer.getFeedLastModified(FEEDID)));
        this.buffer.addDeleted(e.getId(),FEEDID);
        // time will be set inside the buffer
        assertTrue(firstAddTimestamp < this.buffer.getFeedLastModified(FEEDID));
        
        
    
public voidtestGetSortedEntries()

        assertNull(this.buffer.getSortedEntries(FEEDID));
        ServerBaseEntry e = createServerBaseEntry("2",FEEDID);
        e.setUpdated(new DateTime(System.currentTimeMillis()-200,0));
        StorageEntryWrapper wrapper = new StorageEntryWrapper(e,StorageOperation.INSERT);
        this.buffer.addEntry(wrapper);
        e.setId("0");
//      force timestamp
        e.setUpdated(new DateTime(System.currentTimeMillis()-180,0));
        wrapper = new StorageEntryWrapper(e,StorageOperation.INSERT);
        this.buffer.addEntry(wrapper);
        e.setId("1");
//      force timestamp
        e.setUpdated(new DateTime(System.currentTimeMillis()-160,0));
        wrapper = new StorageEntryWrapper(e,StorageOperation.INSERT);
        this.buffer.addEntry(wrapper);
        e.setId("0");
//      force timestamp
        e.setUpdated(new DateTime(System.currentTimeMillis()-140,0));
        wrapper = new StorageEntryWrapper(e,StorageOperation.UPDATE);
        this.buffer.addEntry(wrapper);
//      force timestamp
        e.setUpdated(new DateTime(System.currentTimeMillis()-120,0));
        wrapper = new StorageEntryWrapper(e,StorageOperation.DELETE);
        this.buffer.addEntry(wrapper);
        List<StorageEntryWrapper> list = this.buffer.getSortedEntries(FEEDID);
       assertEquals(3,list.size());
        for (int i = 0; i < 3; i++) {
            assertEquals(""+i,list.get(i).getEntryId());   
        }
        

    
public voidtestStorageBuffer()

        assertEquals(StorageBuffer.DEFAULT_BUFFER_COUNT,new StorageBuffer(StorageBuffer.DEFAULT_BUFFER_COUNT-1).getBufferSize());
        assertEquals(StorageBuffer.DEFAULT_BUFFER_COUNT,new StorageBuffer(StorageBuffer.DEFAULT_BUFFER_COUNT).getBufferSize());
        assertEquals(StorageBuffer.DEFAULT_BUFFER_COUNT+1,new StorageBuffer(StorageBuffer.DEFAULT_BUFFER_COUNT+1).getBufferSize());