Search in sources :

Example 6 with AsyncMetadataVersionManager

use of voldemort.client.scheduler.AsyncMetadataVersionManager in project voldemort by voldemort.

the class AsyncMetadataVersionManagerTest method testStoreDefinitionChangeTracker.

/*
     * Validates that the AsyncMetadataVersionManager correctly identifies the
     * store specific version update. This is done by initializing the base
     * metadata version (for a particular store), starting the
     * AsyncMetadataVersionManager and then updating the version to a new value.
     * For the test to succeed the callback has to be invoked correctly by the
     * asynchronous manager.
     */
@Test(timeout = 60000)
public void testStoreDefinitionChangeTracker() {
    String storeVersionKey = "users";
    Callable<Void> rebootstrapCallback = new Callable<Void>() {

        public Void call() throws Exception {
            callbackForStoreChange();
            return null;
        }
    };
    try {
        // Write a base version of 100
        Properties versionProps = MetadataVersionStoreUtils.getProperties(this.sysVersionStore);
        versionProps.setProperty(storeVersionKey, Long.toString(100));
        MetadataVersionStoreUtils.setProperties(this.sysVersionStore, versionProps);
        // Giving enough time to complete the above put.
        Thread.sleep(500);
        // Starting the Version Metadata Manager
        this.asyncCheckMetadata = new AsyncMetadataVersionManager(this.repository, rebootstrapCallback, storeVersionKey);
        scheduler.schedule(asyncCheckMetadata.getClass().getName(), asyncCheckMetadata, new Date(), 500);
        // Wait until the Version Manager is active
        while (!asyncCheckMetadata.isActive) {
            Thread.sleep(500);
        }
        // Updating the version metadata here for the Version Metadata
        // Manager to detect
        this.newVersion = 101;
        System.err.println("Incrementing the version for : " + storeVersionKey);
        versionProps.setProperty(storeVersionKey, Long.toString(this.newVersion));
        MetadataVersionStoreUtils.setProperties(this.sysVersionStore, versionProps);
        while (!callbackDone) {
            Thread.sleep(2000);
        }
        assertEquals(false, (this.updatedStoreVersion == 0));
        assertEquals(this.updatedStoreVersion, this.newVersion);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed to start the Metadata Version Manager : " + e.getMessage());
    }
}
Also used : AsyncMetadataVersionManager(voldemort.client.scheduler.AsyncMetadataVersionManager) Properties(java.util.Properties) Callable(java.util.concurrent.Callable) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Date (java.util.Date)6 AsyncMetadataVersionManager (voldemort.client.scheduler.AsyncMetadataVersionManager)6 Callable (java.util.concurrent.Callable)5 Properties (java.util.Properties)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 ClientConfig (voldemort.client.ClientConfig)2 SystemStoreRepository (voldemort.client.SystemStoreRepository)2 SchedulerService (voldemort.common.service.SchedulerService)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 Before (org.junit.Before)1 BootstrapFailureException (voldemort.client.BootstrapFailureException)1 SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)1 SystemStoreClientFactory (voldemort.client.SystemStoreClientFactory)1 SerializerDefinition (voldemort.serialization.SerializerDefinition)1 VoldemortServer (voldemort.server.VoldemortServer)1 StoreDefinition (voldemort.store.StoreDefinition)1 StoreDefinitionBuilder (voldemort.store.StoreDefinitionBuilder)1