Skip to content

Commit

Permalink
HSEARCH-2366 Make tests compatible with non-default build
Browse files Browse the repository at this point in the history
- don't use 11+ Files API
- use a version of ES including the distribution part
  • Loading branch information
marko-bekhta committed Mar 27, 2023
1 parent 94d3188 commit 724d2c6
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.hibernate.search.backend.elasticsearch.cfg.ElasticsearchIndexSettings;
import org.hibernate.search.engine.backend.schema.management.spi.IndexSchemaCollector;
Expand Down Expand Up @@ -77,12 +79,18 @@ public void indexSchema(Optional<String> backendName, String indexName, SchemaEx
" }" +
" }" +
"}",
Files.readString( directory.resolve( testIndexName ).resolve( "create-index.json" ) )
readString( directory.resolve( testIndexName ).resolve( "create-index.json" ) )
);

assertJsonEquals(
"{}",
Files.readString( directory.resolve( testIndexName ).resolve( "create-index-query-params.json" ) )
readString( directory.resolve( testIndexName ).resolve( "create-index-query-params.json" ) )
);
}

private String readString(Path path) throws IOException {
try ( Stream<String> lines = Files.lines( path ) ) {
return lines.collect( Collectors.joining( "\n" ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.persistence.EntityManagerFactory;

import org.hibernate.search.integrationtest.mapper.orm.realbackend.testsupport.BackendConfigurations;
Expand Down Expand Up @@ -45,7 +47,7 @@ public void elasticsearch() throws IOException {
osVersion -> false
)
);
String version = ElasticsearchTestDialect.getActualVersion().versionString();
String version = ElasticsearchTestDialect.getActualVersion().toString();
entityManagerFactory = setupHelper.start()
// so that we don't try to do anything with the schema and allow to run without ES being up:
.withProperty( "hibernate.search.schema_management.strategy", "none" )
Expand Down Expand Up @@ -84,7 +86,7 @@ public void elasticsearch() throws IOException {
" }," +
" \"settings\": {}" +
"}",
Files.readString(
readString(
directory.resolve( "backend" ) // as we are using the default backend
.resolve( "indexes" )
.resolve( Book.NAME )
Expand All @@ -93,7 +95,7 @@ public void elasticsearch() throws IOException {

assertJsonEquals(
"{}",
Files.readString(
readString(
directory.resolve( "backend" ) // as we are using the default backend
.resolve( "indexes" )
.resolve( Book.NAME )
Expand Down Expand Up @@ -129,7 +131,7 @@ public void elasticsearch() throws IOException {
" }," +
" \"settings\": {}" +
"}",
Files.readString(
readString(
directory.resolve( "backends" ) // as we are not using the default backend
.resolve( Article.BACKEND_NAME ) // name of a backend
.resolve( "indexes" )
Expand All @@ -139,12 +141,18 @@ public void elasticsearch() throws IOException {

assertJsonEquals(
"{}",
Files.readString(
readString(
directory.resolve( "backends" ) // as we are not using the default backend
.resolve( Article.BACKEND_NAME ) // name of a backend
.resolve( "indexes" )
.resolve( Article.NAME )
.resolve( "create-index-query-params.json" ) )
);
}

private String readString(Path path) throws IOException {
try ( Stream<String> lines = Files.lines( path ) ) {
return lines.collect( Collectors.joining( "\n" ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.persistence.EntityManagerFactory;

import org.hibernate.search.integrationtest.mapper.orm.realbackend.testsupport.BackendConfigurations;
Expand Down Expand Up @@ -43,19 +45,25 @@ public void lucene() throws IOException {
Path directory = temporaryFolder.newFolder().toPath();
Search.mapping( entityManagerFactory ).scope( Object.class ).schemaManager().exportExpectedSchema( directory );

String bookIndex = Files.readString(
String bookIndex = readString(
directory.resolve( "backend" ) // as we are using the default backend
.resolve( "indexes" )
.resolve( Book.NAME )
.resolve( "no-schema.txt" ) );
assertThat( bookIndex ).isEqualTo( "The Lucene backend does not support exporting the schema." );

String articleIndex = Files.readString(
String articleIndex = readString(
directory.resolve( "backends" ) // as we are not using the default backend
.resolve( Article.BACKEND_NAME ) // name of a backend
.resolve( "indexes" )
.resolve( Article.NAME )
.resolve( "no-schema.txt" ) );
assertThat( articleIndex ).isEqualTo( "The Lucene backend does not support exporting the schema." );
}

private String readString(Path path) throws IOException {
try ( Stream<String> lines = Files.lines( path ) ) {
return lines.collect( Collectors.joining( "\n" ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
import static org.junit.Assume.assumeFalse;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.hibernate.search.integrationtest.mapper.pojo.standalone.realbackend.testsupport.BackendConfigurations;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId;
Expand Down Expand Up @@ -43,7 +48,7 @@ public class ElasticsearchSchemaManagerExporterIT {

@Before
public void setUp() throws Exception {
String version = ElasticsearchTestDialect.getActualVersion().versionString();
String version = ElasticsearchTestDialect.getActualVersion().toString();
this.mapping = setupHelper.start()
// so that we don't try to do anything with the schema and allow to run without ES being up:
.withProperty( "hibernate.search.schema_management.strategy", "none" )
Expand Down Expand Up @@ -92,7 +97,7 @@ public void elasticsearch() throws IOException {
" }," +
" \"settings\": {}" +
"}",
Files.readString(
readString(
directory.resolve( "backend" ) // as we are using the default backend
.resolve( "indexes" )
.resolve( Book.NAME )
Expand All @@ -101,7 +106,7 @@ public void elasticsearch() throws IOException {

assertJsonEquals(
"{}",
Files.readString(
readString(
directory.resolve( "backend" ) // as we are using the default backend
.resolve( "indexes" )
.resolve( Book.NAME )
Expand Down Expand Up @@ -136,7 +141,7 @@ public void elasticsearch() throws IOException {
" }," +
" \"settings\": {}" +
"}",
Files.readString(
readString(
directory.resolve( "backends" ) // as we are not using the default backend
.resolve( Article.BACKEND_NAME ) // name of a backend
.resolve( "indexes" )
Expand All @@ -146,7 +151,7 @@ public void elasticsearch() throws IOException {

assertJsonEquals(
"{}",
Files.readString(
readString(
directory.resolve( "backends" ) // as we are not using the default backend
.resolve( Article.BACKEND_NAME ) // name of a backend
.resolve( "indexes" )
Expand All @@ -162,7 +167,7 @@ public void exportToExistingDirectory() throws IOException {
.resolve( "indexes" )
.resolve( Book.NAME )
);
Files.writeString(
writeString(
path
.resolve( "not-an-index.json" ),
"{}"
Expand All @@ -186,7 +191,7 @@ public void exportToExistingFile() throws IOException {
Path path = Files.createDirectories( directory.resolve( "backend" )
.resolve( "indexes" )
);
Files.writeString(
writeString(
path.resolve( Book.NAME ),
"{}"
);
Expand Down Expand Up @@ -254,4 +259,17 @@ public void setTitle(String title) {
this.title = title;
}
}

private String readString(Path path) throws IOException {
try ( Stream<String> lines = Files.lines( path ) ) {
return lines.collect( Collectors.joining( "\n" ) );
}
}

private void writeString(Path path, String string) throws IOException {
try ( OutputStream outputStream = Files.newOutputStream( path );
OutputStreamWriter writer = new OutputStreamWriter( outputStream, StandardCharsets.UTF_8 ) ) {
writer.write( string );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.lang.invoke.MethodHandles;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.hibernate.search.integrationtest.mapper.pojo.standalone.realbackend.testsupport.BackendConfigurations;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId;
Expand Down Expand Up @@ -44,14 +46,14 @@ public void lucene() throws IOException {
Path directory = temporaryFolder.newFolder().toPath();
mapping.scope( Object.class ).schemaManager().exportExpectedSchema( directory );

String bookIndex = Files.readString(
String bookIndex = readString(
directory.resolve( "backend" ) // as we are using the default backend
.resolve( "indexes" )
.resolve( Book.NAME )
.resolve( "no-schema.txt" ) );
assertThat( bookIndex ).isEqualTo( "The Lucene backend does not support exporting the schema." );

String articleIndex = Files.readString(
String articleIndex = readString(
directory.resolve( "backends" ) // as we are not using the default backend
.resolve( Article.BACKEND_NAME ) // name of a backend
.resolve( "indexes" )
Expand Down Expand Up @@ -111,4 +113,10 @@ public void setTitle(String title) {
this.title = title;
}
}

private String readString(Path path) throws IOException {
try ( Stream<String> lines = Files.lines( path ) ) {
return lines.collect( Collectors.joining( "\n" ) );
}
}
}

0 comments on commit 724d2c6

Please sign in to comment.