Search in sources :

Example 1 with IterationStatistic

use of com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic in project conquery by bakdata.

the class SerializingStoreDumpTest method testCorruptKeyDump.

/**
 * Tests if entries with corrupted keys are dumped.
 */
@Test
public void testCorruptKeyDump() throws IOException {
    // Set dump directory to this tests temp-dir
    config.setUnreadableDataDumpDirectory(tmpDir);
    {
        // Open a store and insert a valid key-value pair (UserId & User)
        SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
        store.add(new UserId("testU1"), user);
    }
    {
        // Open that store again, with a different config to insert a corrupt entry
        // (String & ManagedQuery)
        SerializingStore<String, QueryDescription> store = createSerializedStore(config, env, Validators.newValidator(), new StoreInfo<>(USER_STORE_ID.getName(), String.class, QueryDescription.class));
        store.add("not a valid conquery Id", cQuery);
    }
    {
        // Reopen the store with the initial value and try to iterate over all entries
        // (this triggers the dump or removal of invalid entries)
        SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
        IterationStatistic expectedResult = new IterationStatistic();
        expectedResult.setTotalProcessed(2);
        expectedResult.setFailedKeys(1);
        expectedResult.setFailedValues(0);
        // Iterate (do nothing with the entries themselves)
        IterationStatistic result = store.forEach((k, v, s) -> {
        });
        assertThat(result).isEqualTo(expectedResult);
    }
    // Test if the correct number of dumpfiles was generated
    Condition<File> dumpFileCond = new Condition<>(f -> f.getName().endsWith(SerializingStore.DUMP_FILE_EXTENTION), "dump file");
    assertThat(tmpDir.listFiles()).areExactly(1, dumpFileCond);
    // Test if the dump is correct
    File dumpFile = getDumpFile(dumpFileCond);
    assertThat((QueryDescription) Jackson.MAPPER.readerFor(QueryDescription.class).readValue(dumpFile)).isEqualTo(cQuery);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) Validators(io.dropwizard.jersey.validation.Validators) Environments(jetbrains.exodus.env.Environments) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) StoreMappings(com.bakdata.conquery.io.storage.StoreMappings) Environment(jetbrains.exodus.env.Environment) Files(com.google.common.io.Files) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) IterationStatistic(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic) Validator(javax.validation.Validator) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) User(com.bakdata.conquery.models.auth.entities.User) File(java.io.File) Dataset(com.bakdata.conquery.models.datasets.Dataset) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) Slf4j(lombok.extern.slf4j.Slf4j) AfterEach(org.junit.jupiter.api.AfterEach) Condition(org.assertj.core.api.Condition) CQReusedQuery(com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery) Jackson(com.bakdata.conquery.io.jackson.Jackson) XodusStoreFactory(com.bakdata.conquery.models.config.XodusStoreFactory) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) Condition(org.assertj.core.api.Condition) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) IterationStatistic(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with IterationStatistic

use of com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic in project conquery by bakdata.

the class SerializingStoreDumpTest method testCorruptValueDump.

/**
 * Tests if entries with corrupted values are dumped.
 */
@Test
public void testCorruptValueDump() throws IOException {
    // Set dump directory to this tests temp-dir
    config.setUnreadableDataDumpDirectory(tmpDir);
    {
        // Open a store and insert a valid key-value pair (UserId & User)
        SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
        store.add(user.getId(), user);
    }
    {
        // Open that store again, with a different config to insert a corrupt entry
        // (UserId & ManagedQuery)
        SerializingStore<UserId, QueryDescription> store = createSerializedStore(config, env, Validators.newValidator(), new StoreInfo<>(USER_STORE_ID.getName(), UserId.class, QueryDescription.class));
        store.add(new UserId("testU2"), cQuery);
    }
    {
        // Reopen the store with the initial value and try to iterate over all entries
        // (this triggers the dump or removal of invalid entries)
        SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
        IterationStatistic expectedResult = new IterationStatistic();
        expectedResult.setTotalProcessed(2);
        expectedResult.setFailedKeys(0);
        expectedResult.setFailedValues(1);
        // Iterate (do nothing with the entries themselves)
        IterationStatistic result = store.forEach((k, v, s) -> {
        });
        assertThat(result).isEqualTo(expectedResult);
    }
    // Test if the correct number of dumpfiles was generated
    Condition<File> dumpFileCond = new Condition<>(f -> f.getName().endsWith(SerializingStore.DUMP_FILE_EXTENTION), "dump file");
    assertThat(tmpDir.listFiles()).areExactly(1, dumpFileCond);
    // Test if the dump is correct
    File dumpFile = getDumpFile(dumpFileCond);
    assertThat((QueryDescription) Jackson.MAPPER.readerFor(QueryDescription.class).readValue(dumpFile)).isEqualTo(cQuery);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) Validators(io.dropwizard.jersey.validation.Validators) Environments(jetbrains.exodus.env.Environments) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) StoreMappings(com.bakdata.conquery.io.storage.StoreMappings) Environment(jetbrains.exodus.env.Environment) Files(com.google.common.io.Files) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) IterationStatistic(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic) Validator(javax.validation.Validator) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) User(com.bakdata.conquery.models.auth.entities.User) File(java.io.File) Dataset(com.bakdata.conquery.models.datasets.Dataset) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) Slf4j(lombok.extern.slf4j.Slf4j) AfterEach(org.junit.jupiter.api.AfterEach) Condition(org.assertj.core.api.Condition) CQReusedQuery(com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery) Jackson(com.bakdata.conquery.io.jackson.Jackson) XodusStoreFactory(com.bakdata.conquery.models.config.XodusStoreFactory) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) Condition(org.assertj.core.api.Condition) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) IterationStatistic(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 3 with IterationStatistic

use of com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic in project conquery by bakdata.

the class SerializingStoreDumpTest method testCorruptionRemoval.

/**
 * Tests if entries with corrupted are removed from the store if configured so.
 * The dump itself is not testet.
 */
@Test
public void testCorruptionRemoval() {
    log.info("This test will throw some warnings from the SerializingStore.");
    // Set config to remove corrupt entries
    config.setRemoveUnreadableFromStore(true);
    {
        // Open a store and insert a valid key-value pair (UserId & User)
        SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
        store.add(new UserId("testU1"), user);
    }
    {
        // Insert two corrupt entries. One with a corrupt key and the other one with a
        // corrupt value
        {
            SerializingStore<String, QueryDescription> store = createSerializedStore(config, env, Validators.newValidator(), new StoreInfo<>(USER_STORE_ID.getName(), String.class, QueryDescription.class));
            store.add("not a valid conquery Id", cQuery);
        }
        {
            SerializingStore<UserId, QueryDescription> store = createSerializedStore(config, env, Validators.newValidator(), new StoreInfo<>(USER_STORE_ID.getName(), UserId.class, QueryDescription.class));
            store.add(new UserId("testU2"), cQuery);
        }
    }
    {
        // Reopen the store with correct configuration and try to iterate over all
        // entries (this triggers the dump or removal of invalid entries)
        SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
        IterationStatistic expectedResult = new IterationStatistic();
        expectedResult.setTotalProcessed(3);
        expectedResult.setFailedKeys(1);
        expectedResult.setFailedValues(1);
        // Iterate (do nothing with the entries themselves)
        IterationStatistic result = store.forEach((k, v, s) -> {
        });
        assertThat(result).isEqualTo(expectedResult);
    }
    {
        // Reopen again to check that the corrupted values have been removed previously
        SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
        IterationStatistic expectedResult = new IterationStatistic();
        expectedResult.setTotalProcessed(1);
        expectedResult.setFailedKeys(0);
        expectedResult.setFailedValues(0);
        // Iterate (do nothing with the entries themselves)
        IterationStatistic result = store.forEach((k, v, s) -> {
        });
        assertThat(result).isEqualTo(expectedResult);
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) Validators(io.dropwizard.jersey.validation.Validators) Environments(jetbrains.exodus.env.Environments) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) StoreMappings(com.bakdata.conquery.io.storage.StoreMappings) Environment(jetbrains.exodus.env.Environment) Files(com.google.common.io.Files) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) IterationStatistic(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic) Validator(javax.validation.Validator) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) User(com.bakdata.conquery.models.auth.entities.User) File(java.io.File) Dataset(com.bakdata.conquery.models.datasets.Dataset) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) Slf4j(lombok.extern.slf4j.Slf4j) AfterEach(org.junit.jupiter.api.AfterEach) Condition(org.assertj.core.api.Condition) CQReusedQuery(com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery) Jackson(com.bakdata.conquery.io.jackson.Jackson) XodusStoreFactory(com.bakdata.conquery.models.config.XodusStoreFactory) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) IterationStatistic(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) Test(org.junit.jupiter.api.Test)

Aggregations

ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)3 QueryDescription (com.bakdata.conquery.apiv1.query.QueryDescription)3 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)3 Jackson (com.bakdata.conquery.io.jackson.Jackson)3 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)3 StoreMappings (com.bakdata.conquery.io.storage.StoreMappings)3 IterationStatistic (com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic)3 User (com.bakdata.conquery.models.auth.entities.User)3 XodusStoreFactory (com.bakdata.conquery.models.config.XodusStoreFactory)3 Dataset (com.bakdata.conquery.models.datasets.Dataset)3 UserId (com.bakdata.conquery.models.identifiable.ids.specific.UserId)3 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)3 NonPersistentStoreFactory (com.bakdata.conquery.util.NonPersistentStoreFactory)3 Files (com.google.common.io.Files)3 Validators (io.dropwizard.jersey.validation.Validators)3 File (java.io.File)3 IOException (java.io.IOException)3 Objects (java.util.Objects)3 Validator (javax.validation.Validator)3 Environment (jetbrains.exodus.env.Environment)3