Search in sources :

Example 1 with CodeBasePublication3

use of io.codekvast.javaagent.model.v3.CodeBasePublication3 in project codekvast by crispab.

the class IntakeIntegrationTest method should_ignore_already_imported_codeBasePublication3.

@Test
public void should_ignore_already_imported_codeBasePublication3() {
    // 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("invocations"), is(0));
    CodeBaseEntry3 entry1 = CodeBaseEntry3.sampleCodeBaseEntry();
    CodeBaseEntry3 entry2 = CodeBaseEntry3.sampleCodeBaseEntry().toBuilder().signature(entry1.getSignature() + "2").build();
    long now = System.currentTimeMillis();
    CodeBasePublication3 publication1 = CodeBasePublication3.builder().commonData(CommonPublicationData2.sampleCommonPublicationData().toBuilder().codeBaseFingerprint("fingerprint1").publishedAtMillis(now).build()).entries(asList(entry1)).build();
    // when
    codeBaseImporter.importPublication(publication1);
    // then
    assertThat(countRowsInTable("methods"), is(1));
    assertThat(countRowsInTable("codebase_fingerprints WHERE publishedAt = ?", Timestamp.from(Instant.ofEpochMilli(now).truncatedTo(ChronoUnit.MILLIS))), is(1));
    // given
    CodeBasePublication3 publication2 = CodeBasePublication3.builder().commonData(CommonPublicationData2.sampleCommonPublicationData().toBuilder().codeBaseFingerprint("fingerprint1").publishedAtMillis(now + 1000).build()).entries(asList(entry1, entry2)).build();
    // when
    codeBaseImporter.importPublication(publication2);
    // then
    assertThat(countRowsInTable("methods"), is(1));
    assertThat(countRowsInTable("codebase_fingerprints WHERE publishedAt = ?", Timestamp.from(Instant.ofEpochMilli(now + 1000).truncatedTo(ChronoUnit.MILLIS))), is(1));
}
Also used : CodeBasePublication3(io.codekvast.javaagent.model.v3.CodeBasePublication3) CodeBaseEntry3(io.codekvast.javaagent.model.v3.CodeBaseEntry3) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 2 with CodeBasePublication3

use of io.codekvast.javaagent.model.v3.CodeBasePublication3 in project codekvast by crispab.

the class IntakeIntegrationTest method should_import_codeBasePublication3_with_too_long_signature_entry.

@Test
public void should_import_codeBasePublication3_with_too_long_signature_entry() {
    // given
    assertThat(countRowsInTable("applications"), is(0));
    assertThat(countRowsInTable("environments"), is(0));
    assertThat(countRowsInTable("jvms"), is(0));
    assertThat(countRowsInTable("packages"), is(0));
    assertThat(countRowsInTable("types"), is(0));
    assertThat(countRowsInTable("methods"), is(0));
    assertThat(countRowsInTable("invocations"), is(0));
    CodeBaseEntry3 entry1 = CodeBaseEntry3.sampleCodeBaseEntry();
    CodeBaseEntry3 entry2 = entry1.toBuilder().signature(SYNTHETIC_SIGNATURE).build();
    int signatureLength = DatabaseLimits.MAX_METHOD_SIGNATURE_LENGTH + 1;
    int indexLength = DatabaseLimits.MAX_METHOD_SIGNATURE_INDEX_LENGTH;
    CodeBaseEntry3 entry3 = entry1.toBuilder().signature(RandomStringUtils.randomAlphanumeric(signatureLength - 2) + "()").build();
    CodeBasePublication3 publication = CodeBasePublication3.builder().commonData(CommonPublicationData2.sampleCommonPublicationData()).entries(asList(entry1, entry2, entry3, entry3)).build();
    // when
    codeBaseImporter.importPublication(publication);
    // 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("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 = ?", entry2.getSignature()), is(0));
    assertThat(countRowsInTable("methods WHERE signature = ?", entry3.getSignature()), is(0));
    assertThat(countRowsInTable("truncated_signatures WHERE signature = ?", entry3.getSignature()), is(1));
    assertThat(countRowsInTable("methods WHERE signature LIKE ?", entry3.getSignature().substring(0, signatureLength - 3) + "...%"), is(0));
    assertThat(countRowsInTable("methods WHERE signature LIKE ?", entry3.getSignature().substring(0, indexLength) + "%"), is(1));
    assertThat(countRowsInTable("method_locations WHERE location = ?", entry1.getMethodSignature().getLocation()), is(2));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = 0"), is(2));
    assertThat(countRowsInTable("invocations WHERE status = ?", NOT_INVOKED.name()), is(2));
}
Also used : CodeBasePublication3(io.codekvast.javaagent.model.v3.CodeBasePublication3) CodeBaseEntry3(io.codekvast.javaagent.model.v3.CodeBaseEntry3) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with CodeBasePublication3

use of io.codekvast.javaagent.model.v3.CodeBasePublication3 in project codekvast by crispab.

the class IntakeIntegrationTest method should_import_invocationDataPublication_then_codeBasePublication.

@Test
public void should_import_invocationDataPublication_then_codeBasePublication() {
    // 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));
    CommonPublicationData2 commonData = CommonPublicationData2.sampleCommonPublicationData();
    CodeBaseEntry3 codeBaseEntry = CodeBaseEntry3.sampleCodeBaseEntry();
    CodeBasePublication3 codeBasePublication = CodeBasePublication3.builder().commonData(commonData).entries(asList(codeBaseEntry)).build();
    val signature = codeBaseEntry.getSignature();
    long intervalStartedAtMillis = System.currentTimeMillis();
    InvocationDataPublication2 invocationDataPublication = InvocationDataPublication2.builder().commonData(commonData).recordingIntervalStartedAtMillis(intervalStartedAtMillis).invocations(singleton(signature)).build();
    // when
    invocationDataImporter.importPublication(invocationDataPublication);
    // 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 WHERE signature = ?", signature), is(1));
    assertThat(countRowsInTable("method_locations"), is(0));
    assertThat(countRowsInTable("invocations"), is(1));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = ?", intervalStartedAtMillis), is(1));
    assertThat(countRowsInTable("invocations WHERE status = ?", INVOKED.name()), is(1));
    // given
    long intervalStartedAtMillis2 = intervalStartedAtMillis + 3600;
    // when
    invocationDataImporter.importPublication(invocationDataPublication.toBuilder().recordingIntervalStartedAtMillis(intervalStartedAtMillis2).build());
    // then
    assertThat(countRowsInTable("invocations"), is(1));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = ?", intervalStartedAtMillis2), is(1));
    assertThat(countRowsInTable("invocations WHERE status = ?", INVOKED.name()), is(1));
    // when
    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 WHERE signature = ?", signature), is(1));
    assertThat(countRowsInTable("method_locations WHERE location = ?", codeBaseEntry.getMethodSignature().getLocation()), is(1));
    assertThat(countRowsInTable("invocations"), is(1));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = ?", intervalStartedAtMillis2), is(1));
    assertThat(countRowsInTable("invocations WHERE status = ?", INVOKED.name()), is(1));
}
Also used : lombok.val(lombok.val) 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 4 with CodeBasePublication3

use of io.codekvast.javaagent.model.v3.CodeBasePublication3 in project codekvast by crispab.

the class IntakeIntegrationTest method should_import_codeBasePublication3.

@Test
public void should_import_codeBasePublication3() {
    // given
    assertThat(countRowsInTable("applications"), is(0));
    assertThat(countRowsInTable("environments"), is(0));
    assertThat(countRowsInTable("jvms"), is(0));
    assertThat(countRowsInTable("packages"), is(0));
    assertThat(countRowsInTable("types"), is(0));
    assertThat(countRowsInTable("methods"), is(0));
    assertThat(countRowsInTable("invocations"), is(0));
    CodeBaseEntry3 entry1 = CodeBaseEntry3.sampleCodeBaseEntry();
    CodeBasePublication3 publication = CodeBasePublication3.builder().commonData(CommonPublicationData2.sampleCommonPublicationData()).entries(asList(entry1, entry1.toBuilder().signature(SYNTHETIC_SIGNATURE).build())).build();
    // when
    codeBaseImporter.importPublication(publication);
    // 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("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("method_locations WHERE location = ?", entry1.getMethodSignature().getLocation()), is(1));
    assertThat(countRowsInTable("invocations WHERE invokedAtMillis = 0"), is(1));
    assertThat(countRowsInTable("invocations WHERE status = ?", NOT_INVOKED.name()), is(1));
}
Also used : CodeBasePublication3(io.codekvast.javaagent.model.v3.CodeBasePublication3) CodeBaseEntry3(io.codekvast.javaagent.model.v3.CodeBaseEntry3) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with CodeBasePublication3

use of io.codekvast.javaagent.model.v3.CodeBasePublication3 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)

Aggregations

CodeBasePublication3 (io.codekvast.javaagent.model.v3.CodeBasePublication3)6 CodeBaseEntry3 (io.codekvast.javaagent.model.v3.CodeBaseEntry3)5 Test (org.junit.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 CommonPublicationData2 (io.codekvast.javaagent.model.v2.CommonPublicationData2)2 InvocationDataPublication2 (io.codekvast.javaagent.model.v2.InvocationDataPublication2)2 CodekvastPublishingException (io.codekvast.javaagent.publishing.CodekvastPublishingException)1 File (java.io.File)1 IOException (java.io.IOException)1 lombok.val (lombok.val)1