Search in sources :

Example 91 with EnumSource

use of org.junit.jupiter.params.provider.EnumSource in project neo4j by neo4j.

the class ReadAheadChannelTest method shouldReturnValueIfSufficientBytesAreBufferedEvenIfEOFHasBeenEncountered.

@ParameterizedTest
@EnumSource(Constructors.class)
void shouldReturnValueIfSufficientBytesAreBufferedEvenIfEOFHasBeenEncountered(Constructor constructor) throws Exception {
    // Given
    Path shortReadTestFile = Path.of("shortReadTest.txt");
    StoreChannel storeChannel = fileSystem.write(shortReadTestFile);
    ByteBuffer buffer = ByteBuffers.allocate(1, INSTANCE);
    buffer.put((byte) 1);
    buffer.flip();
    storeChannel.writeAll(buffer);
    storeChannel.force(false);
    storeChannel.close();
    storeChannel = fileSystem.read(shortReadTestFile);
    ReadAheadChannel<StoreChannel> channel = constructor.apply(storeChannel, DEFAULT_READ_AHEAD_SIZE);
    assertThrows(ReadPastEndException.class, channel::getShort);
    assertEquals((byte) 1, channel.get());
    assertThrows(ReadPastEndException.class, channel::get);
}
Also used : Path(java.nio.file.Path) StoreChannel(org.neo4j.io.fs.StoreChannel) ByteBuffer(java.nio.ByteBuffer) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 92 with EnumSource

use of org.junit.jupiter.params.provider.EnumSource in project neo4j by neo4j.

the class ReadAheadChannelTest method validateChecksumOverStream.

@ParameterizedTest
@EnumSource(Constructors.class)
void validateChecksumOverStream(Constructor constructor) throws Exception {
    // given
    Checksum checksum = CHECKSUM_FACTORY.get();
    int checksumValue;
    Path file = Path.of("foo.1");
    try (StoreChannel storeChannel = fileSystem.write(file)) {
        ByteBuffer buffer = ByteBuffers.allocate(6, INSTANCE);
        buffer.put((byte) 1);
        checksum.update(1);
        buffer.put((byte) 2);
        checksum.update(2);
        checksumValue = (int) checksum.getValue();
        buffer.putInt(checksumValue);
        buffer.flip();
        storeChannel.writeAll(buffer);
        storeChannel.force(false);
    }
    ReadAheadChannel<StoreChannel> bufferedReader = constructor.apply(fileSystem.read(file), DEFAULT_READ_AHEAD_SIZE);
    assertEquals(1, bufferedReader.get());
    assertEquals(2, bufferedReader.get());
    assertEquals(checksumValue, bufferedReader.endChecksumAndValidate());
    assertEquals(6, bufferedReader.position());
}
Also used : Path(java.nio.file.Path) Checksum(java.util.zip.Checksum) StoreChannel(org.neo4j.io.fs.StoreChannel) ByteBuffer(java.nio.ByteBuffer) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 93 with EnumSource

use of org.junit.jupiter.params.provider.EnumSource in project neo4j by neo4j.

the class IndexSamplingIntegrationTest method shouldSampleNotUniqueIndex.

@ParameterizedTest
@EnumSource(Entity.class)
void shouldSampleNotUniqueIndex(Entity entity) throws Throwable {
    GraphDatabaseService db;
    DatabaseManagementService managementService = null;
    long deletedNodes = 0;
    try {
        // Given
        managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
        db = managementService.database(DEFAULT_DATABASE_NAME);
        try (Transaction tx = db.beginTx()) {
            entity.createIndex(tx, schemaName, TOKEN, property);
            tx.commit();
        }
        try (Transaction tx = db.beginTx()) {
            tx.schema().awaitIndexOnline(schemaName, 1, TimeUnit.MINUTES);
            tx.commit();
        }
        try (Transaction tx = db.beginTx()) {
            for (int i = 0; i < entities; i++) {
                entity.createEntity(tx, TOKEN, property, names[i % names.length]);
            }
            tx.commit();
        }
        try (Transaction tx = db.beginTx()) {
            for (int i = 0; i < (entities / 10); i++) {
                entity.deleteFirstFound(tx, TOKEN, property, names[i % names.length]);
                deletedNodes++;
            }
            tx.commit();
        }
    } finally {
        if (managementService != null) {
            managementService.shutdown();
        }
    }
    // When
    triggerIndexResamplingOnNextStartup();
    // Then
    // lucene will consider also the delete nodes, native won't
    var indexSample = fetchIndexSamplingValues();
    assertThat(indexSample.uniqueValues()).as("Unique values").isEqualTo(names.length);
    assertThat(indexSample.sampleSize()).as("Sample size").isGreaterThanOrEqualTo(entities - deletedNodes).isLessThanOrEqualTo(entities);
    // but regardless, the deleted nodes should not be considered in the index size value
    assertThat(indexSample.updates()).as("Updates").isEqualTo(0);
    assertThat(indexSample.indexSize()).as("Index size").isEqualTo(entities - deletedNodes);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 94 with EnumSource

use of org.junit.jupiter.params.provider.EnumSource in project neo4j by neo4j.

the class FulltextProceduresTest method standardFoldingAnalyzerMustFindNonASCIILettersByTheirFolding.

@ParameterizedTest
@EnumSource(SearchString.class)
void standardFoldingAnalyzerMustFindNonASCIILettersByTheirFolding(SearchString searchString) {
    // Given
    // Fulltext index with analyzer: 'standard-folding'
    String indexName = createNodeFulltextIndexWithStandardFoldingAnalyzer();
    char[] nonAsciiLetterArray = NON_ASCII_LETTERS.toCharArray();
    // and
    // a folding from non ascii characters to ascii strings
    Map<Character, String> nonAsciiCharsToFolding = getFoldingOfChars(nonAsciiLetterArray);
    // When
    // Nodes with non Ascii characters
    Map<Character, Long> nonAsciiCharsToNodeId = new HashMap<>();
    String propPrefix = "123";
    String propSuffix = "345";
    try (Transaction tx = db.beginTx()) {
        for (Map.Entry<Character, String> charToFolding : nonAsciiCharsToFolding.entrySet()) {
            Node node = tx.createNode(LABEL);
            Character character = charToFolding.getKey();
            // To make sure no properties are filtered out because of accidental match with stopwords
            // we surround the non ascii letter with prefix and suffix. We use a number to avoid false
            // positives when searching.
            String propValue = propPrefix + character + propSuffix;
            node.setProperty(PROP, propValue);
            long id = node.getId();
            nonAsciiCharsToNodeId.put(character, id);
        }
        tx.commit();
    }
    // Should find with exact match and wildcard
    try (Transaction tx = db.beginTx()) {
        for (char nonAsciiChar : nonAsciiLetterArray) {
            Long expectedNodeId = nonAsciiCharsToNodeId.get(nonAsciiChar);
            assertAtLeastSingleHitOnSearch(indexName, expectedNodeId, tx, searchString.searchString(nonAsciiChar, propPrefix, propSuffix));
        }
        tx.commit();
    }
}
Also used : HashMap(java.util.HashMap) Node(org.neo4j.graphdb.Node) Transaction(org.neo4j.graphdb.Transaction) Map(java.util.Map) HashMap(java.util.HashMap) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 95 with EnumSource

use of org.junit.jupiter.params.provider.EnumSource in project neo4j by neo4j.

the class SingleInstanceGetRoutingTableProcedureTest method shouldThrowWhenHostCtxIsInvalid.

@ParameterizedTest
@EnumSource(value = RoutingMode.class)
void shouldThrowWhenHostCtxIsInvalid(RoutingMode routingMode) {
    // given
    var ctxContents = new MapValueBuilder();
    ctxContents.add(ADDRESS_CONTEXT_KEY, Values.stringValue("not a socket address"));
    var ctx = ctxContents.build();
    var config = newConfig(Config.defaults(SERVER_DEFAULTS), Duration.ofSeconds(100), new SocketAddress("neo4j.com", 7687));
    config.set(routing_default_router, routingMode);
    var portRegister = mock(ConnectorPortRegister.class);
    var databaseManager = databaseManagerMock(config, true);
    var logProvider = new AssertableLogProvider();
    var procedure = newProcedure(databaseManager, portRegister, config, logProvider);
    var expectedMessage = "An address key is included in the query string provided to the GetRoutingTableProcedure, but its value could not be parsed.";
    // when/then
    assertThrows(ProcedureException.class, () -> invoke(procedure, ID, ctx), expectedMessage);
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

EnumSource (org.junit.jupiter.params.provider.EnumSource)396 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)392 Account (io.nem.symbol.sdk.model.account.Account)40 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)38 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)34 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)34 Address (io.nem.symbol.sdk.model.account.Address)30 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)27 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)26 TransactionSearchCriteria (io.nem.symbol.sdk.api.TransactionSearchCriteria)26 BigInteger (java.math.BigInteger)25 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)23 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)23 EntityUpdates (org.neo4j.storageengine.api.EntityUpdates)21 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)19 Path (java.nio.file.Path)18 ArrayList (java.util.ArrayList)16 Listener (io.nem.symbol.sdk.api.Listener)15 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)15 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)14