Search in sources :

Example 1 with CodeBaseEntry2

use of io.codekvast.javaagent.model.v2.CodeBaseEntry2 in project codekvast by crispab.

the class ImportDAOImpl method importNewMethods.

private void importNewMethods(long customerId, long publishedAtMillis, Collection<CodeBaseEntry2> entries, Map<String, Long> existingMethods) {
    long startedAtMillis = System.currentTimeMillis();
    int count = 0;
    for (CodeBaseEntry2 entry : entries) {
        String signature = entry.getSignature();
        if (!existingMethods.containsKey(signature)) {
            existingMethods.put(signature, doInsertRow(new InsertCompleteMethodStatement(customerId, publishedAtMillis, entry.getMethodSignature(), entry.getVisibility(), entry.getSignature())));
            count += 1;
        }
    }
    logger.debug("Imported {} methods in {} ms", count, System.currentTimeMillis() - startedAtMillis);
}
Also used : CodeBaseEntry2(io.codekvast.javaagent.model.v2.CodeBaseEntry2)

Example 2 with CodeBaseEntry2

use of io.codekvast.javaagent.model.v2.CodeBaseEntry2 in project codekvast by crispab.

the class CodeBaseEntry2Test method should_transform_from_v1_format.

@SuppressWarnings("deprecation")
@Test
public void should_transform_from_v1_format() {
    CodeBaseEntry e1 = CodeBaseEntry.sampleCodeBaseEntry();
    CodeBaseEntry2 e2 = CodeBaseEntry2.sampleCodeBaseEntry();
    assertThat(CodeBaseEntry2.fromV1Format(e1), is(e2));
}
Also used : CodeBaseEntry(io.codekvast.javaagent.model.v1.CodeBaseEntry) CodeBaseEntry2(io.codekvast.javaagent.model.v2.CodeBaseEntry2) Test(org.junit.Test)

Example 3 with CodeBaseEntry2

use of io.codekvast.javaagent.model.v2.CodeBaseEntry2 in project codekvast by crispab.

the class IntakeIntegrationTest method should_import_codeBasePublication2.

@Test
public void should_import_codeBasePublication2() {
    // given
    assertThat(countRowsInTable("applications"), is(0));
    assertThat(countRowsInTable("environments"), is(0));
    assertThat(countRowsInTable("jvms"), is(0));
    assertThat(countRowsInTable("codebase_fingerprints"), is(0));
    assertThat(countRowsInTable("packages"), is(0));
    assertThat(countRowsInTable("types"), is(0));
    assertThat(countRowsInTable("methods"), is(0));
    assertThat(countRowsInTable("method_locations"), is(0));
    assertThat(countRowsInTable("invocations"), is(0));
    CodeBaseEntry2 entry1 = CodeBaseEntry2.sampleCodeBaseEntry();
    CodeBasePublication2 publication = CodeBasePublication2.builder().commonData(CommonPublicationData2.sampleCommonPublicationData()).entries(asList(entry1, entry1.toBuilder().signature(SYNTHETIC_SIGNATURE).build())).build();
    File file = writeToTempFile(publication);
    // when
    publicationImporter.importPublicationFile(file);
    // then
    assertThat(countRowsInTable("applications WHERE name = ?", publication.getCommonData().getAppName()), is(1));
    assertThat(countRowsInTable("environments WHERE name = ?", publication.getCommonData().getEnvironment()), is(1));
    assertThat(countRowsInTable("jvms WHERE uuid = ?", publication.getCommonData().getJvmUuid()), is(1));
    assertThat(countRowsInTable("methods WHERE signature = ?", entry1.getSignature()), is(1));
    assertThat(countRowsInTable("codebase_fingerprints WHERE codeBaseFingerprint = ?", publication.getCommonData().getCodeBaseFingerprint()), is(1));
    assertThat(countRowsInTable("method_locations"), // location is not supported in CodeBaseEntry2
    is(0));
    assertThat(countRowsInTable("packages WHERE name = ?", entry1.getMethodSignature().getPackageName()), is(1));
    assertThat(countRowsInTable("types WHERE name = ?", entry1.getMethodSignature().getDeclaringType()), is(1));
    assertThat(countRowsInTable("methods WHERE signature = ?", entry1.getSignature()), is(1));
    assertThat(countRowsInTable("methods WHERE signature = ?", SYNTHETIC_SIGNATURE), is(0));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = 0"), is(1));
    assertThat(countRowsInTable("invocations WHERE status = ?", NOT_INVOKED.name()), is(1));
}
Also used : CodeBasePublication2(io.codekvast.javaagent.model.v2.CodeBasePublication2) CodeBaseEntry2(io.codekvast.javaagent.model.v2.CodeBaseEntry2) File(java.io.File) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with CodeBaseEntry2

use of io.codekvast.javaagent.model.v2.CodeBaseEntry2 in project codekvast by crispab.

the class IntakeIntegrationTest method should_import_codeBasePublication_then_invocationDataPublication_twice.

@Test
public void should_import_codeBasePublication_then_invocationDataPublication_twice() {
    // given
    assertThat(countRowsInTable("applications"), is(0));
    assertThat(countRowsInTable("environments"), is(0));
    assertThat(countRowsInTable("jvms"), is(0));
    assertThat(countRowsInTable("methods"), is(0));
    assertThat(countRowsInTable("invocations"), is(0));
    String signature1 = "signature1";
    String signature2 = "signature2";
    CodeBaseEntry3 codeBaseEntry1 = CodeBaseEntry3.sampleCodeBaseEntry().toBuilder().signature(signature1).build();
    CodeBaseEntry3 codeBaseEntry2 = CodeBaseEntry3.sampleCodeBaseEntry().toBuilder().signature(signature2).build();
    CommonPublicationData2 commonData = CommonPublicationData2.sampleCommonPublicationData();
    CodeBasePublication3 codeBasePublication = CodeBasePublication3.builder().commonData(commonData).entries(asList(codeBaseEntry1, codeBaseEntry2)).build();
    // when Import a code base with two distinct signatures
    codeBaseImporter.importPublication(codeBasePublication);
    // then
    assertThat(countRowsInTable("applications WHERE name = ?", codeBasePublication.getCommonData().getAppName()), is(1));
    assertThat(countRowsInTable("environments WHERE name = ?", codeBasePublication.getCommonData().getEnvironment()), is(1));
    assertThat(countRowsInTable("jvms WHERE uuid = ?", codeBasePublication.getCommonData().getJvmUuid()), is(1));
    assertThat(countRowsInTable("methods"), is(2));
    assertThat(countRowsInTable("methods WHERE signature = ?", signature1), is(1));
    assertThat(countRowsInTable("methods WHERE signature = ?", signature2), is(1));
    assertThat(countRowsInTable("method_locations"), is(2));
    assertThat(countRowsInTable("invocations"), is(2));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = 0"), is(2));
    assertThat(countRowsInTable("invocations WHERE status = ?", NOT_INVOKED.name()), is(2));
    // given
    long intervalStartedAtMillis1 = System.currentTimeMillis();
    InvocationDataPublication2 invocationDataPublication1 = InvocationDataPublication2.builder().commonData(commonData).recordingIntervalStartedAtMillis(intervalStartedAtMillis1).invocations(singleton(signature1)).build();
    long intervalStartedAtMillis2 = intervalStartedAtMillis1 + 3600;
    InvocationDataPublication2 invocationDataPublication2 = invocationDataPublication1.toBuilder().recordingIntervalStartedAtMillis(intervalStartedAtMillis2).build();
    // when Record the invocation of one of the signatures twice in reversed time order
    invocationDataImporter.importPublication(invocationDataPublication2);
    invocationDataImporter.importPublication(invocationDataPublication1);
    // then
    assertThat(countRowsInTable("invocations"), is(2));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = ?", 0), is(1));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = ?", intervalStartedAtMillis1), is(0));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = ?", intervalStartedAtMillis2), is(1));
    assertThat(countRowsInTable("invocations WHERE status = ?", NOT_INVOKED.name()), is(1));
    assertThat(countRowsInTable("invocations WHERE status = ?", INVOKED.name()), is(1));
    // given
    setSecurityContextCustomerId(commonData.getCustomerId());
}
Also used : CommonPublicationData2(io.codekvast.javaagent.model.v2.CommonPublicationData2) CodeBasePublication3(io.codekvast.javaagent.model.v3.CodeBasePublication3) CodeBaseEntry3(io.codekvast.javaagent.model.v3.CodeBaseEntry3) InvocationDataPublication2(io.codekvast.javaagent.model.v2.InvocationDataPublication2) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with CodeBaseEntry2

use of io.codekvast.javaagent.model.v2.CodeBaseEntry2 in project codekvast by crispab.

the class ImportDAOImpl method ensureInitialInvocations.

private void ensureInitialInvocations(CommonPublicationData2 data, long customerId, long appId, long environmentId, long jvmId, Collection<CodeBaseEntry2> entries, Map<String, Long> existingMethods, Set<Long> existingInvocations) {
    long startedAtMillis = System.currentTimeMillis();
    int importCount = 0;
    for (CodeBaseEntry2 entry : entries) {
        long methodId = existingMethods.get(entry.getSignature());
        if (!existingInvocations.contains(methodId)) {
            SignatureStatus2 initialStatus = calculateInitialStatus(data, entry);
            jdbcTemplate.update(new InsertInvocationStatement(customerId, appId, environmentId, jvmId, methodId, initialStatus, 0L, 0L));
            existingInvocations.add(methodId);
            importCount += 1;
        }
    }
    logger.debug("Imported {} invocations in {} ms", importCount, System.currentTimeMillis() - startedAtMillis);
}
Also used : SignatureStatus2(io.codekvast.javaagent.model.v2.SignatureStatus2) CodeBaseEntry2(io.codekvast.javaagent.model.v2.CodeBaseEntry2)

Aggregations

CodeBaseEntry2 (io.codekvast.javaagent.model.v2.CodeBaseEntry2)5 Test (org.junit.Test)4 CodeBasePublication2 (io.codekvast.javaagent.model.v2.CodeBasePublication2)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 CodeBaseEntry (io.codekvast.javaagent.model.v1.CodeBaseEntry)1 CodeBasePublication (io.codekvast.javaagent.model.v1.CodeBasePublication)1 CommonPublicationData2 (io.codekvast.javaagent.model.v2.CommonPublicationData2)1 InvocationDataPublication2 (io.codekvast.javaagent.model.v2.InvocationDataPublication2)1 SignatureStatus2 (io.codekvast.javaagent.model.v2.SignatureStatus2)1 CodeBaseEntry3 (io.codekvast.javaagent.model.v3.CodeBaseEntry3)1 CodeBasePublication3 (io.codekvast.javaagent.model.v3.CodeBasePublication3)1 File (java.io.File)1