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

TestRecoverController

public class TestRecoverController 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 RecoverController
writeController
private RecoverController
readController
private File
recDir
private String
feedId
private String
entryId
Constructors Summary
Methods Summary
private voidcreateCorruptedFile()

        File file = new File(this.recDir,"somefile.rec");
        file.deleteOnExit();
        FileWriter writer = new FileWriter(file);
        writer.write("someString\nSomeOtherString");
        writer.close();
    
protected voidsetUp()

    
         
        this.recDir = new File("unittest"+System.currentTimeMillis());
        if(!this.recDir.exists())
            this.recDir.mkdir();
        this.recDir.deleteOnExit();
        GDataServerRegistry.getRegistry().registerService(new ProvidedServiceStub());
        this.writeController = new RecoverController(this.recDir,false,true);
        this.readController = new RecoverController(this.recDir,true,true);
        
        

        
    
protected voidtearDown()

        
        
        
        File[] files = this.recDir.listFiles();
        for (int i = 0; i < files.length; i++) {
            files[i].delete();
        }
        this.recDir.delete();
      GDataServerRegistry.getRegistry().destroy();
    
public voidtestRecoverEntries()

        testStorageModified();
        
        int length = this.recDir.listFiles().length;
        assertEquals(1,length);
        
        this.readController.initialize();
        try{
        this.readController.recoverEntries(new StorageModifierStub(null,null,null,0,0));
        }catch (Exception e) {
            fail("unexpected exception"+e.getMessage());
        }
        this.readController.destroy();
        assertEquals(1,this.recDir.listFiles().length);
        
        createCorruptedFile();
        this.readController.initialize();
        try{
        this.readController.recoverEntries(new StorageModifierStub(null,null,null,0,0));
        }catch (Exception e) {
            fail("unexpected exception"+e.getMessage());
        }
        this.readController.destroy();
        assertEquals(2,this.recDir.listFiles().length);
    
public voidtestStorageModified()

        this.writeController.initialize();
        ServerBaseEntry entry = new ServerBaseEntry();
        entry.setFeedId(this.feedId);
        entry.setId(entryId);
        entry.setUpdated(DateTime.now());
        entry.setServiceConfig(new ProvidedServiceStub());
        StorageEntryWrapper wrapper = new StorageEntryWrapper(entry,StorageOperation.INSERT);
        this.writeController.storageModified(wrapper);
        assertEquals(1,this.recDir.listFiles().length);
        this.writeController.destroy();