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);
}
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());
}
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);
}
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();
}
}
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);
}
Aggregations