Search in sources :

Example 16 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class DatabaseStateProcedure method extractDatabaseId.

protected NamedDatabaseId extractDatabaseId(AnyValue[] input) throws ProcedureException {
    if (input.length != 1) {
        throw new IllegalArgumentException("Illegal input:" + Arrays.toString(input));
    }
    var rawName = input[0];
    if (!(rawName instanceof TextValue)) {
        throw new IllegalArgumentException(format("Parameter '%s' value should have a string representation. Instead: %s", PARAMETER_NAME, rawName));
    }
    var name = new NormalizedDatabaseName(((TextValue) rawName).stringValue());
    return idRepository.getByName(name).orElseThrow(() -> new ProcedureException(DatabaseNotFound, format("Unable to retrieve the status " + "for database with name %s because no database with this name exists!", name)));
}
Also used : TextValue(org.neo4j.values.storable.TextValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) NormalizedDatabaseName(org.neo4j.configuration.helpers.NormalizedDatabaseName)

Example 17 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class DuplicateCheckStrategyTest method duplicateFoundAmongUniqueStringSingleProperty.

@ParameterizedTest
@MethodSource("duplicateCheckStrategies")
void duplicateFoundAmongUniqueStringSingleProperty(DuplicateCheckStrategy checkStrategy) throws IndexEntryConflictException {
    for (int i = 0; i < randomNumberOfEntries(); i++) {
        String propertyValue = String.valueOf(i);
        TextValue stringValue = Values.stringValue(propertyValue);
        checkStrategy.checkForDuplicate(stringValue, i);
    }
    int duplicateTarget = BUCKET_STRATEGY_ENTRIES_THRESHOLD - 2;
    String duplicate = String.valueOf(duplicateTarget);
    TextValue duplicatedValue = Values.stringValue(duplicate);
    var e = assertThrows(IndexEntryConflictException.class, () -> checkStrategy.checkForDuplicate(duplicatedValue, 3));
    assertEquals(format("Both node %d and node 3 share the property value %s", duplicateTarget, ValueTuple.of(duplicatedValue)), e.getMessage());
}
Also used : TextValue(org.neo4j.values.storable.TextValue) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 18 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class PrettyPrinterTest method shouldBeAbleToUseAnyQuoteMark.

@Test
void shouldBeAbleToUseAnyQuoteMark() {
    // Given
    TextValue hello = stringValue("(ツ)");
    PrettyPrinter printer = new PrettyPrinter("__", FULL);
    // When
    hello.writeTo(printer);
    // Then
    assertThat(printer.value()).isEqualTo("__(ツ)__");
}
Also used : TextValue(org.neo4j.values.storable.TextValue) Test(org.junit.jupiter.api.Test)

Example 19 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class SchemaComplianceCheckerTest method shouldReportNotUniquelyIndexed.

@Test
void shouldReportNotUniquelyIndexed() throws Exception {
    // given
    LabelSchemaDescriptor descriptor = forLabel(label1, propertyKey1);
    long indexId = uniqueIndex(descriptor);
    long nodeId;
    try (AutoCloseable ignored = tx()) {
        TextValue value = stringValue("a");
        // (N1) indexed w/ property A
        {
            long propId = propertyStore.nextId(CursorContext.NULL);
            nodeId = node(nodeStore.nextId(CursorContext.NULL), propId, NULL, label1);
            property(propId, NULL, NULL, propertyValue(propertyKey1, value));
            indexValue(descriptor, indexId, nodeId, value);
        }
        // (N2) indexed w/ property A
        {
            long propId = propertyStore.nextId(CursorContext.NULL);
            long nodeId2 = node(nodeStore.nextId(CursorContext.NULL), propId, NULL, label1);
            property(propId, NULL, NULL, propertyValue(propertyKey1, value));
            indexValue(descriptor, indexId, nodeId2, value);
        }
    }
    // when
    checkIndexed(nodeId);
    // then
    expect(ConsistencyReport.NodeConsistencyReport.class, report -> report.uniqueIndexNotUnique(any(), any(), anyLong()));
}
Also used : TextValue(org.neo4j.values.storable.TextValue) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.jupiter.api.Test)

Example 20 with TextValue

use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.

the class DbIndexesFailureMessageIT method listAllIndexesWithFailedIndex.

@Test
void listAllIndexesWithFailedIndex() throws Throwable {
    // Given
    KernelTransaction dataTransaction = newTransaction(AUTH_DISABLED);
    String labelName = "Fail";
    String propertyKey = "foo";
    int failedLabel = dataTransaction.tokenWrite().labelGetOrCreateForName(labelName);
    int propertyKeyId1 = dataTransaction.tokenWrite().propertyKeyGetOrCreateForName(propertyKey);
    this.transaction.createNode(Label.label(labelName)).setProperty(propertyKey, "some value");
    commit();
    KernelTransaction transaction = newTransaction(AUTH_DISABLED);
    LabelSchemaDescriptor schema = forLabel(failedLabel, propertyKeyId1);
    IndexDescriptor index = transaction.schemaWrite().indexCreate(schema, "fail foo index");
    commit();
    try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
        assertThrows(IllegalStateException.class, () -> tx.schema().awaitIndexesOnline(2, MINUTES));
    }
    // When
    RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "indexDetails")).id(), new TextValue[] { stringValue(index.getName()) }, ProcedureCallContext.EMPTY);
    assertTrue(stream.hasNext());
    AnyValue[] result = stream.next();
    assertFalse(stream.hasNext());
    // Commit procedure transaction
    commit();
    // Then
    assertEquals(longValue(index.getId()), result[0]);
    assertEquals(stringValue("fail foo index"), result[1]);
    assertEquals(stringValue("FAILED"), result[2]);
    assertEquals(doubleValue(0.0), result[3]);
    assertEquals(stringValue("NONUNIQUE"), result[4]);
    assertEquals(stringValue("BTREE"), result[5]);
    assertEquals(stringValue("NODE"), result[6]);
    assertEquals(VirtualValues.list(stringValue(labelName)), result[7]);
    assertEquals(VirtualValues.list(stringValue(propertyKey)), result[8]);
    assertEquals(stringValue(NATIVE_BTREE10.providerName()), result[9]);
    assertMapsEqual(index.getIndexConfig().asMap(), (MapValue) result[10]);
    assertThat(((TextValue) result[11]).stringValue()).contains("java.lang.RuntimeException: Fail on update during population");
    assertEquals(12, result.length);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TextValue(org.neo4j.values.storable.TextValue) AnyValue(org.neo4j.values.AnyValue) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Aggregations

TextValue (org.neo4j.values.storable.TextValue)29 Test (org.junit.jupiter.api.Test)12 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)7 AnyValue (org.neo4j.values.AnyValue)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 BooleanValue (org.neo4j.values.storable.BooleanValue)6 Config (org.neo4j.configuration.Config)5 Value (org.neo4j.values.storable.Value)5 Arrays (java.util.Arrays)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ArrayUtils.toArray (org.apache.commons.lang3.ArrayUtils.toArray)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Matchers.contains (org.hamcrest.Matchers.contains)4 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 Public (org.neo4j.annotations.Public)4 CapabilitiesRegistry (org.neo4j.capabilities.CapabilitiesRegistry)4