FileDocCategorySizeDatePackage
TestIndexLogReader.javaAPI DocApache Lucene 2.1.04440Wed Feb 14 10:46:02 GMT 2007org.apache.lucene.gdata.search.index

TestIndexLogReader

public class TestIndexLogReader extends TestCase
author
Simon Willnauer

Fields Summary
File
logFile
Map
actions
Constructors Summary
Methods Summary
protected voidsetUp()

        this.logFile = new File(System.getProperty("java.io.tmpdir"),"log");
        this.logFile.deleteOnExit();
        this.logFile.createNewFile();
        this.actions = new HashMap<String,IndexAction>();
   
        
    
protected voidtearDown()

        super.tearDown();
        this.logFile.delete();
    
public voidtestReadIndexLog()

        writeLog().close();
        
        Map<String,IndexAction> readActionMap = new HashMap<String,IndexAction>();
        IndexLogReader.readIndexLog(this.logFile,readActionMap);
        Set<String> keySet = this.actions.keySet();
        assertEquals(10,keySet.size());
        for (String string : keySet) {
            assertTrue(readActionMap.get(string).equals(actions.get(string)));
        }
        
       
        
    
public voidtestReadIndexLogFixLogFile()

        writeLog();
          
        Map<String,IndexAction> readActionMap = IndexLogReader.readIndexLog(this.logFile,null);
        Set<String> keySet = this.actions.keySet();
        assertEquals(10,keySet.size());
        for (String string : keySet) {
            assertTrue(readActionMap.get(string).equals(actions.get(string)));
        }
        
    
public voidtestReadIndexLogNoInputMap()

        writeLog().close();
      
        Map<String,IndexAction> readActionMap = IndexLogReader.readIndexLog(this.logFile,null);
        Set<String> keySet = this.actions.keySet();
        assertEquals(10,keySet.size());
        for (String string : keySet) {
            assertTrue(readActionMap.get(string).equals(actions.get(string)));
        }
        
    
public voidtestWriterClosed()

        IndexLogWriter writer = writeLog();
        writer.close();
        try{
            writer.writeAction(null,null);
            fail("writer is closed");
        }catch (IllegalStateException e) {
          
        }
        try{
            writer.close();
            fail("writer is closed");
        }catch (IllegalStateException e) {
          
        }
        
        
    
private IndexLogWriterwriteLog()

        this.actions = new HashMap<String,IndexAction>();
        IndexLogWriter writer = new IndexLogWriter(this.logFile);
        boolean totwice = true;
        for (int i = 0; i < 10; i++) {
            IndexAction a = null;
            if(i%3 ==0)
                a= IndexAction.INSERT;
            if(i%3 ==1)
                a= IndexAction.UPDATE;
            if(i%3 ==2)
                a= IndexAction.DELETE;
            this.actions.put(""+i,a);
            writer.writeAction(""+i,a);
            /*
             * double action
             */
            if(i == 9 && totwice){
                i = 0;
                totwice = false;
            }
        }
        return writer;