Search in sources :

Example 1 with MockTime

use of voldemort.MockTime in project voldemort by voldemort.

the class DataCleanupJobTest method testStoreDeletion.

@Test
public void testStoreDeletion() throws InterruptedException {
    SchedulerService scheduler = new SchedulerService(1, time);
    String cleanUpJobName = "cleanup-freq-test";
    try {
        MockTime mockTime = new MockTime(System.currentTimeMillis());
        ScanPermitWrapper scanWrapper = new ScanPermitWrapper(1);
        // clean up will purge everything older than last 2 seconds
        DataCleanupJob cleanupJob = new DataCleanupJob<ByteArray, byte[], byte[]>(engine, new ScanPermitWrapper(1), STORE_NAME, mockTime, metadataStore);
        // and will run every 3 seconds starting now
        scheduler.schedule(cleanUpJobName, cleanupJob, new Date(), 1 * Time.MS_PER_SECOND);
        // Insert records that should be deleted when the DataCleanUp Job
        // runs
        putWithTimeStamp(0, 10, System.currentTimeMillis() - 8 * Time.MS_PER_DAY);
        Thread.sleep(3 * Time.MS_PER_SECOND);
        // All of them should be deleted.
        assertAbsence(0, 10);
        // Delete the store.
        metadataStore.deleteStoreDefinition(STORE_NAME);
        // Wait 2 seconds to give the Scheduler job, come out of the
        // previous scan if any
        Thread.sleep(2 * Time.MS_PER_SECOND);
        // Intermittent failure, means problem with the code which needs to be fixed.
        for (int i = 0; i < 1000; i++) {
            assertEquals("Deleted store should never acquire a scan permit", 1, scanWrapper.availablePermits());
        }
    } finally {
        scheduler.terminate(cleanUpJobName);
        scheduler.stop();
    }
}
Also used : SchedulerService(voldemort.common.service.SchedulerService) ScanPermitWrapper(voldemort.server.storage.ScanPermitWrapper) DataCleanupJob(voldemort.server.scheduler.DataCleanupJob) MockTime(voldemort.MockTime) Date(java.util.Date) Test(org.junit.Test)

Example 2 with MockTime

use of voldemort.MockTime in project voldemort by voldemort.

the class CachedCallableTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(inner.call()).thenReturn(CALL_RESULT);
    mockTime = new MockTime();
    cachedCallable = new CachedCallable<Long>(inner, CACHE_TTL_MS, mockTime);
}
Also used : MockTime(voldemort.MockTime) Before(org.junit.Before)

Example 3 with MockTime

use of voldemort.MockTime in project voldemort by voldemort.

the class DataCleanupJobTest method testCleanupFrequency.

@Test
public void testCleanupFrequency() throws InterruptedException {
    SchedulerService scheduler = new SchedulerService(1, time);
    String cleanUpJobName = "cleanup-freq-test";
    try {
        MockTime mockTime = new MockTime(System.currentTimeMillis());
        // clean up will purge everything older than last 2 seconds
        DataCleanupJob cleanupJob = new DataCleanupJob<ByteArray, byte[], byte[]>(engine, new ScanPermitWrapper(1), STORE_NAME, mockTime, metadataStore);
        // and will run every 3 seconds starting now
        scheduler.schedule(cleanUpJobName, cleanupJob, new Date(), 1 * Time.MS_PER_SECOND);
        // load some data
        putWithTimeStamp(0, 10, System.currentTimeMillis());
        Thread.sleep(3 * Time.MS_PER_SECOND);
        // None of the keys should have been deleted
        assertPresence(0, 10);
        assertEquals("No entries must be deleted now", 0, cleanupJob.getEntriesDeleted());
        assertTrue("Entries are scanned, but not deleted", cleanupJob.getEntriesScanned() > 0);
        // Increase the mockTime by a day and a millisecond.
        mockTime.setTime(System.currentTimeMillis() + START_RETENTION * Time.MS_PER_DAY + 1);
        // load some more data
        putWithTimeStamp(10, 20, mockTime.getMilliseconds());
        // give time for data cleanup to run
        Thread.sleep(3 * Time.MS_PER_SECOND);
        // first batch of writes should have been deleted
        assertAbsence(0, 10);
        // and later ones retained.
        assertPresence(10, 20);
        assertEquals("10 entries should be deleted", 10, cleanupJob.getEntriesDeleted());
        // Insert 10 keys that are separated by a day and millisecond
        long currentTime = mockTime.getMilliseconds();
        for (int i = 20; i < 30; i++) {
            currentTime += Time.MS_PER_DAY + 1;
            putWithTimeStamp(i, i + 1, currentTime);
        }
        mockTime.setTime(currentTime);
        updateStoreDef(REDUCED_RETENTION);
        Thread.sleep(3 * Time.MS_PER_SECOND);
        assertAbsence(10, 28);
        assertEquals("28 entries should be deleted", 28, cleanupJob.getEntriesDeleted());
        // Only last 2 keys should be present, third key is old by 2 days
        // and 2 milliseconds
        assertPresence(28, 30);
    } finally {
        scheduler.terminate(cleanUpJobName);
        scheduler.stop();
    }
}
Also used : SchedulerService(voldemort.common.service.SchedulerService) ScanPermitWrapper(voldemort.server.storage.ScanPermitWrapper) DataCleanupJob(voldemort.server.scheduler.DataCleanupJob) MockTime(voldemort.MockTime) Date(java.util.Date) Test(org.junit.Test)

Example 4 with MockTime

use of voldemort.MockTime in project voldemort by voldemort.

the class DataCleanupJobTest method setUp.

@Before
public void setUp() throws Exception {
    time = new MockTime();
    storeDir = TestUtils.createTempDir();
    FileDeleteStrategy.FORCE.delete(storeDir);
    // lets use all the default values.
    Props props = new Props();
    props.put("node.id", 1);
    props.put("voldemort.home", "test/common/voldemort/config");
    VoldemortConfig voldemortConfig = new VoldemortConfig(props);
    voldemortConfig.setBdbCacheSize(1024 * 1024);
    voldemortConfig.setBdbOneEnvPerStore(true);
    voldemortConfig.setBdbDataDirectory(storeDir.toURI().getPath());
    voldemortConfig.setBdbPrefixKeysWithPartitionId(prefixPartitionId);
    bdbStorage = new BdbStorageConfiguration(voldemortConfig);
    StoreDefinition storeDef = getStoreDef(START_RETENTION);
    engine = bdbStorage.getStore(storeDef, TestUtils.makeSingleNodeRoutingStrategy());
    List<Node> nodes = Lists.newArrayList();
    nodes.add(new Node(0, "test-host", 1234, 1235, 1236, Arrays.asList(0)));
    Cluster cluster = new Cluster("cluster", nodes);
    StoreRepository repo = new StoreRepository();
    repo.setSlopStore(new SlopStorageEngine(new InMemoryStorageEngine<ByteArray, byte[], byte[]>("slop"), cluster));
    repo.addNodeStore(0, engine);
    metadataStore = ServerTestUtils.createMetadataStore(cluster, Arrays.asList(storeDef));
}
Also used : InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) StoreDefinition(voldemort.store.StoreDefinition) Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) StoreRepository(voldemort.server.StoreRepository) SlopStorageEngine(voldemort.store.slop.SlopStorageEngine) Props(voldemort.utils.Props) BdbStorageConfiguration(voldemort.store.bdb.BdbStorageConfiguration) MockTime(voldemort.MockTime) VoldemortConfig(voldemort.server.VoldemortConfig) Before(org.junit.Before)

Example 5 with MockTime

use of voldemort.MockTime in project voldemort by voldemort.

the class RepairJobTest method setUp.

public void setUp() {
    File temp = TestUtils.createTempDir();
    VoldemortConfig config = new VoldemortConfig(0, temp.getAbsolutePath());
    new File(config.getMetadataDirectory()).mkdir();
    this.serverMap = new HashMap<Integer, VoldemortServer>();
    this.scheduler = new SchedulerService(1, new MockTime());
    this.cluster = VoldemortTestConstants.getNineNodeCluster();
    StoreDefinitionsMapper mapper = new StoreDefinitionsMapper();
    this.storeDefs = mapper.readStoreList(new StringReader((VoldemortTestConstants.getSingleStore322Xml())));
    this.storeRepository = new StoreRepository();
    this.metadataStore = ServerTestUtils.createMetadataStore(cluster, storeDefs);
    storage = new StorageService(storeRepository, metadataStore, scheduler, config);
    // Start the storage service
    storage.start();
    this.socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 32 * 1024);
    String storeDefsString = mapper.writeStoreList(storeDefs);
    File file = null;
    try {
        file = ServerTestUtils.createTempFile("single-store-", ".xml");
        FileUtils.writeStringToFile(file, storeDefsString);
        String storeDefFile = file.getAbsolutePath();
        List<Integer> nodesToStart = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8);
        // Start the servers
        startServers(cluster, storeDefFile, nodesToStart, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SchedulerService(voldemort.common.service.SchedulerService) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) StoreRepository(voldemort.server.StoreRepository) VoldemortServer(voldemort.server.VoldemortServer) VoldemortConfig(voldemort.server.VoldemortConfig) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) StringReader(java.io.StringReader) File(java.io.File) MockTime(voldemort.MockTime)

Aggregations

MockTime (voldemort.MockTime)6 SchedulerService (voldemort.common.service.SchedulerService)4 Before (org.junit.Before)3 StoreRepository (voldemort.server.StoreRepository)3 File (java.io.File)2 Date (java.util.Date)2 Test (org.junit.Test)2 VoldemortConfig (voldemort.server.VoldemortConfig)2 DataCleanupJob (voldemort.server.scheduler.DataCleanupJob)2 ScanPermitWrapper (voldemort.server.storage.ScanPermitWrapper)2 StringReader (java.io.StringReader)1 Cluster (voldemort.cluster.Cluster)1 Node (voldemort.cluster.Node)1 VoldemortServer (voldemort.server.VoldemortServer)1 StoreDefinition (voldemort.store.StoreDefinition)1 BdbStorageConfiguration (voldemort.store.bdb.BdbStorageConfiguration)1 InMemoryStorageEngine (voldemort.store.memory.InMemoryStorageEngine)1 SlopStorageEngine (voldemort.store.slop.SlopStorageEngine)1 ClientRequestExecutorPool (voldemort.store.socket.clientrequest.ClientRequestExecutorPool)1 Props (voldemort.utils.Props)1