Search in sources :

Example 1 with ConcordObjectMapper

use of com.walmartlabs.concord.server.ConcordObjectMapper in project concord by walmartlabs.

the class ProcessStateManagerTest method testUpdateState.

@Test
public void testUpdateState() throws Exception {
    ProcessKey processKey = new ProcessKey(UUID.randomUUID(), OffsetDateTime.now());
    Path baseDir = Files.createTempDirectory("testImport");
    writeTempFile(baseDir.resolve("file-1"), "123".getBytes());
    writeTempFile(baseDir.resolve("file-2"), "456".getBytes());
    // 
    ProcessKeyCache processKeyCache = new ProcessKeyCache(new ProcessQueueDao(getConfiguration(), new ConcordObjectMapper(new ObjectMapper())));
    ProcessConfiguration stateCfg = new ProcessConfiguration(Duration.of(24, ChronoUnit.HOURS), Collections.singletonList(Constants.Files.CONFIGURATION_FILE_NAME));
    ProcessStateManager stateManager = new ProcessStateManager(getConfiguration(), mock(SecretStoreConfiguration.class), stateCfg, mock(PolicyManager.class), mock(ProcessLogManager.class), processKeyCache);
    stateManager.importPath(processKey, null, baseDir, (p, attrs) -> true);
    Path tmpDir = Files.createTempDirectory("testExport");
    boolean result = stateManager.export(processKey, copyTo(tmpDir));
    assertTrue(result);
    assertFileContent("123", tmpDir.resolve("file-1"));
    assertFileContent("456", tmpDir.resolve("file-2"));
    // --- update
    writeTempFile(baseDir.resolve("file-1"), "123-up".getBytes());
    stateManager.importPath(processKey, null, baseDir, (p, attrs) -> true);
    result = stateManager.export(processKey, copyTo(tmpDir));
    assertTrue(result);
    assertFileContent("123-up", tmpDir.resolve("file-1"));
    assertFileContent("456", tmpDir.resolve("file-2"));
}
Also used : Path(java.nio.file.Path) ProcessKeyCache(com.walmartlabs.concord.server.process.queue.ProcessKeyCache) PolicyManager(com.walmartlabs.concord.server.policy.PolicyManager) ProcessConfiguration(com.walmartlabs.concord.server.cfg.ProcessConfiguration) ConcordObjectMapper(com.walmartlabs.concord.server.ConcordObjectMapper) SecretStoreConfiguration(com.walmartlabs.concord.server.cfg.SecretStoreConfiguration) ProcessLogManager(com.walmartlabs.concord.server.process.logs.ProcessLogManager) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ConcordObjectMapper(com.walmartlabs.concord.server.ConcordObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessQueueDao(com.walmartlabs.concord.server.process.queue.ProcessQueueDao) Test(org.junit.jupiter.api.Test) AbstractDaoTest(com.walmartlabs.concord.server.AbstractDaoTest)

Example 2 with ConcordObjectMapper

use of com.walmartlabs.concord.server.ConcordObjectMapper in project concord by walmartlabs.

the class ProcessStateManagerTest method testLargeImport.

@Test
public void testLargeImport() throws Exception {
    ProcessKey processKey = new ProcessKey(UUID.randomUUID(), OffsetDateTime.now());
    int files = 100;
    int chunkSize = 1024 * 1024;
    int fileSize = 10 * chunkSize;
    byte[] ab = new byte[chunkSize];
    Arrays.fill(ab, (byte) 0);
    Path baseDir = Files.createTempDirectory("test");
    for (int i = 0; i < files; i++) {
        Path p = baseDir.resolve("file" + i);
        try (OutputStream out = Files.newOutputStream(p, StandardOpenOption.CREATE)) {
            for (int j = 0; j < fileSize; j += chunkSize) {
                out.write(ab);
            }
        }
    }
    ProcessKeyCache processKeyCache = new ProcessKeyCache(new ProcessQueueDao(getConfiguration(), new ConcordObjectMapper(new ObjectMapper())));
    ProcessConfiguration stateCfg = new ProcessConfiguration(Duration.of(24, ChronoUnit.HOURS), Collections.singletonList(Constants.Files.CONFIGURATION_FILE_NAME));
    ProcessStateManager stateManager = new ProcessStateManager(getConfiguration(), mock(SecretStoreConfiguration.class), stateCfg, mock(PolicyManager.class), mock(ProcessLogManager.class), processKeyCache);
    stateManager.importPath(processKey, "/", baseDir, (p, attrs) -> true);
}
Also used : Path(java.nio.file.Path) ProcessKeyCache(com.walmartlabs.concord.server.process.queue.ProcessKeyCache) PolicyManager(com.walmartlabs.concord.server.policy.PolicyManager) SecretStoreConfiguration(com.walmartlabs.concord.server.cfg.SecretStoreConfiguration) OutputStream(java.io.OutputStream) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ProcessQueueDao(com.walmartlabs.concord.server.process.queue.ProcessQueueDao) ProcessConfiguration(com.walmartlabs.concord.server.cfg.ProcessConfiguration) ConcordObjectMapper(com.walmartlabs.concord.server.ConcordObjectMapper) ProcessLogManager(com.walmartlabs.concord.server.process.logs.ProcessLogManager) ConcordObjectMapper(com.walmartlabs.concord.server.ConcordObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) AbstractDaoTest(com.walmartlabs.concord.server.AbstractDaoTest)

Example 3 with ConcordObjectMapper

use of com.walmartlabs.concord.server.ConcordObjectMapper in project concord by walmartlabs.

the class SecretDaoTest method testOnCascade.

@Test
public void testOnCascade() {
    UUID orgId = OrganizationManager.DEFAULT_ORG_ID;
    String projectName = "project#" + System.currentTimeMillis();
    ProjectDao projectDao = new ProjectDao(getConfiguration(), new ConcordObjectMapper(TestObjectMapper.INSTANCE));
    UUID projectId = projectDao.insert(orgId, projectName, "test", null, null, null, null, new byte[0], null, null);
    String secretName = "secret#" + System.currentTimeMillis();
    SecretDao secretDao = new SecretDao(getConfiguration());
    UUID secretId = secretDao.insert(orgId, null, secretName, null, SecretType.KEY_PAIR, SecretEncryptedByType.SERVER_KEY, "concord", SecretVisibility.PUBLIC, INSERT);
    secretDao.updateData(secretId, new byte[] { 0, 1, 2 });
    secretDao.update(secretId, secretName, UUID.fromString("4b9d496a-c3a0-4e1b-804c-ac3fccddcb27"), null, new byte[0], null, projectId, orgId);
    String repoName = "repo#" + System.currentTimeMillis();
    RepositoryDao repositoryDao = new RepositoryDao(getConfiguration(), new ConcordObjectMapper(TestObjectMapper.INSTANCE));
    UUID repoId = repositoryDao.insert(projectId, repoName, "n/a", null, null, null, secretId, false, null, false);
    // ---
    secretDao.delete(secretId);
    // ---
    RepositoryEntry r = repositoryDao.get(projectId, repoId);
    assertNotNull(r);
    assertNull(r.getSecretName());
}
Also used : RepositoryDao(com.walmartlabs.concord.server.org.project.RepositoryDao) ConcordObjectMapper(com.walmartlabs.concord.server.ConcordObjectMapper) RepositoryEntry(com.walmartlabs.concord.server.org.project.RepositoryEntry) UUID(java.util.UUID) ProjectDao(com.walmartlabs.concord.server.org.project.ProjectDao) SecretDao(com.walmartlabs.concord.server.org.secret.SecretDao) Test(org.junit.jupiter.api.Test) AbstractDaoTest(com.walmartlabs.concord.server.AbstractDaoTest)

Example 4 with ConcordObjectMapper

use of com.walmartlabs.concord.server.ConcordObjectMapper in project concord by walmartlabs.

the class ProjectDaoTest method setUp.

@BeforeEach
public void setUp() {
    repositoryDao = new RepositoryDao(getConfiguration(), new ConcordObjectMapper(TestObjectMapper.INSTANCE));
    projectDao = new ProjectDao(getConfiguration(), new ConcordObjectMapper(TestObjectMapper.INSTANCE));
}
Also used : RepositoryDao(com.walmartlabs.concord.server.org.project.RepositoryDao) ConcordObjectMapper(com.walmartlabs.concord.server.ConcordObjectMapper) ProjectDao(com.walmartlabs.concord.server.org.project.ProjectDao) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ConcordObjectMapper

use of com.walmartlabs.concord.server.ConcordObjectMapper in project concord by walmartlabs.

the class ProcessKeyCacheTest method testNotFound.

@Test
public void testNotFound() {
    ProcessQueueDao dao = new ProcessQueueDao(getConfiguration(), new ConcordObjectMapper(TestObjectMapper.INSTANCE));
    ProcessKeyCache keyCache = new ProcessKeyCache(dao);
    ProcessKey key = keyCache.get(UUID.randomUUID());
    assertNull(key);
}
Also used : ConcordObjectMapper(com.walmartlabs.concord.server.ConcordObjectMapper) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) Test(org.junit.jupiter.api.Test) AbstractDaoTest(com.walmartlabs.concord.server.AbstractDaoTest)

Aggregations

ConcordObjectMapper (com.walmartlabs.concord.server.ConcordObjectMapper)6 AbstractDaoTest (com.walmartlabs.concord.server.AbstractDaoTest)5 Test (org.junit.jupiter.api.Test)5 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ProcessConfiguration (com.walmartlabs.concord.server.cfg.ProcessConfiguration)2 SecretStoreConfiguration (com.walmartlabs.concord.server.cfg.SecretStoreConfiguration)2 ProjectDao (com.walmartlabs.concord.server.org.project.ProjectDao)2 RepositoryDao (com.walmartlabs.concord.server.org.project.RepositoryDao)2 PolicyManager (com.walmartlabs.concord.server.policy.PolicyManager)2 ProcessLogManager (com.walmartlabs.concord.server.process.logs.ProcessLogManager)2 ProcessKeyCache (com.walmartlabs.concord.server.process.queue.ProcessKeyCache)2 ProcessQueueDao (com.walmartlabs.concord.server.process.queue.ProcessQueueDao)2 Path (java.nio.file.Path)2 RepositoryEntry (com.walmartlabs.concord.server.org.project.RepositoryEntry)1 SecretDao (com.walmartlabs.concord.server.org.secret.SecretDao)1 OutputStream (java.io.OutputStream)1 UUID (java.util.UUID)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1