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

TestStorageImplementation

public class TestStorageImplementation 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 org.apache.lucene.gdata.server.registry.GDataServerRegistry
reg
private org.apache.lucene.gdata.storage.Storage
storage
public static boolean
fail
Constructors Summary
Methods Summary
private java.lang.ThreadgetDelThread(org.apache.lucene.gdata.storage.Storage s, org.apache.lucene.gdata.data.ServerBaseEntry e, boolean conflictExpected)

        Thread t1 = new Thread(new Runner(s, e, conflictExpected,
                StorageOperation.DELETE));
        t1.setPriority(Thread.MAX_PRIORITY);
        return t1;
    
private org.apache.lucene.gdata.utils.VisitorgetMonitorVisitor(java.lang.Object monitor, java.util.concurrent.atomic.AtomicBoolean reached)

        /*
         * The executing thread stops at a defined position while holding the semaphore inside the storageImpl
         */
        return new Visitor(){
          public void execute(Object[] o){
            synchronized (monitor) {
            try {
                reached.set(true);
                monitor.wait();
                reached.set(false);
              
            } catch (InterruptedException e) {
                //                   
            }
            }
          }
        };
    
private java.lang.ThreadgetUpdThread(org.apache.lucene.gdata.storage.Storage s, org.apache.lucene.gdata.data.ServerBaseEntry e, boolean conflictExpected)

        Thread t1 = new Thread(new Runner(s, e, conflictExpected,
                StorageOperation.UPDATE));
        t1.setPriority(Thread.MAX_PRIORITY);
        return t1;
    
protected voidsetUp()


         

        if (reg == null) {
            reg = GDataServerRegistry.getRegistry();
            if(reg.lookup(StorageController.class,ComponentType.STORAGECONTROLLER)!= null);
                reg.destroy();
            reg.registerComponent(StorageCoreControllerStub.class,null);

        }
        this.storage = reg.lookup(StorageController.class,
                ComponentType.STORAGECONTROLLER).getStorage();
    
protected voidtearDown()

        this.storage.close();
        fail = false;
    
public voidtestClose()


    
public voidtestDeleteAccount()


    
public voidtestDeleteEntry()

        try {
            this.storage.storeEntry(null);
            fail("entry is null");
        } catch (StorageException e) {
            //
        }
        ServerBaseEntry entry = new ServerBaseEntry();
        entry.setServiceConfig(new ProvidedServiceStub());
        entry.setId("someID");
        entry.setFeedId("someID");
        try {
            this.storage.storeEntry(entry);

        } catch (StorageException e) {
            fail("unexpected exception");
            //
        }
        entry.setFeedId(null);
        try {
            this.storage.deleteEntry(entry);
            fail("feed is null");
        } catch (StorageException e) {
            //
        }

        entry.setFeedId("someID");
        try {
            this.storage.deleteEntry(entry);

        } catch (StorageException e1) {
            e1.printStackTrace();
            fail("unexpected exception");

        }
        entry.setFeedId("someID");
        
        try {
            this.storage.deleteEntry(entry);

        } catch (StorageException e1) {
            e1.printStackTrace();
            fail("unexpected exception");

        }
        
        
        
        Object monitor = new Object();
        AtomicBoolean reached = new AtomicBoolean(false);

        MultiThreadEntryStub concuEntry = new MultiThreadEntryStub();
        concuEntry.setId(System.currentTimeMillis() + "");
        ProvidedService conf = new ProvidedServiceStub();
        
        concuEntry.setServiceConfig(conf);
        concuEntry.setUpdated(DateTime.now());
        concuEntry.setFeedId("feed");
        this.storage.storeEntry(concuEntry);
        storage.close();
        concuEntry.acceptGetVersionVisitor(getMonitorVisitor(monitor,reached));


        Thread t1 = getDelThread(storage, concuEntry, false);

        Thread t2 = getDelThread(storage, concuEntry, true);
        t1.start();
        /*
         * Wait active -- not nice but works fine here
         * wait until thread parked
         */

        while (true) {
            synchronized (monitor) {
                if (reached.get())
                    break;
                monitor.wait(10);
            }
        }
        t2.start();
        t2.join(800);
        /*
         * Wait active -- not nice but works fine here
         * wake up the waiting thread
         */
        while (true) {
            synchronized (monitor) {
                if (!reached.get())
                    break;
                monitor.notifyAll();
            }
        }
        t1.join(300);
        if (fail)
            fail("thread failed -- see stacktrace");
       
       
    
public voidtestDeleteFeed()


    
public voidtestGetAccount()


    
public voidtestGetAccountNameForFeedId()


    
public voidtestGetEntry()


    
public voidtestGetEntryLastModified()


    
public voidtestGetFeed()


    
public voidtestGetFeedLastModified()


    
public voidtestGetServiceForFeed()


    
public voidtestStoreAccount()


    
public voidtestStoreEntry()


        try {
            this.storage.storeEntry(null);
            fail("entry is null");
        } catch (StorageException e) {
            //
        }
        ServerBaseEntry entry = new ServerBaseEntry();
        entry.setServiceConfig(new ProvidedServiceStub());

        try {
            this.storage.storeEntry(entry);
            fail("feed is null");
        } catch (StorageException e) {
            //
        }

        entry.setFeedId("someID");
        try {
            this.storage.storeEntry(entry);

        } catch (StorageException e1) {
            fail("unexpected exception");

        }
        entry.setServiceConfig(null);
        try {
            this.storage.storeEntry(entry);
            fail("no service config");
        } catch (StorageException e) {

        }
        entry.setVersion(5);
        try {
            this.storage.storeEntry(entry);
            fail("version is greater than 1");
        } catch (StorageException e) {

        }

    
public voidtestStoreFeed()


    
public voidtestUpdateAccount()


    
public voidtestUpdateEntry()

        Object monitor = new Object();
        AtomicBoolean reached = new AtomicBoolean(false);

        MultiThreadEntryStub concuEntry = new MultiThreadEntryStub();
        concuEntry.setId(System.currentTimeMillis() + "");
        ProvidedService conf = new ProvidedServiceStub();
        
        concuEntry.setServiceConfig(conf);
        concuEntry.setUpdated(DateTime.now());
        concuEntry.setFeedId("feed");
        this.storage.storeEntry(concuEntry);
        storage.close();
        concuEntry.acceptGetEntryVisitor(getMonitorVisitor(monitor,reached));


        Thread t1 = getUpdThread(storage, concuEntry, false);

        Thread t2 = getUpdThread(storage, concuEntry, true);
        t1.start();
        /*
         * Wait active -- not nice but works fine here
         * wait until thread parked
         */

        while (true) {
            synchronized (monitor) {
                if (reached.get())
                    break;
                monitor.wait(10);
            }
        }
        t2.start();
        t2.join(800);
        /*
         * Wait active -- not nice but works fine here
         * wake up the waiting thread
         */
        while (true) {
            synchronized (monitor) {
                if (!reached.get())
                    break;
                monitor.notifyAll();
            }
        }
        t1.join(300);
        if (fail)
            fail("thread failed -- see stacktrace");

    
public voidtestUpdateFeed()