Skip to content

Commit

Permalink
Adds testing to the github ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jacomago committed Nov 3, 2023
1 parent a6ea41d commit f0fdce2
Show file tree
Hide file tree
Showing 22 changed files with 437 additions and 328 deletions.
61 changes: 57 additions & 4 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ name: Java CI with Maven

on: [push, pull_request]

permissions:
checks: write

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
Expand All @@ -24,8 +25,60 @@ jobs:
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml

run: mvn --batch-mode --update-snapshots package
- run: mkdir staging && cp target/*.jar staging
- uses: actions/upload-artifact@v3
with:
name: Package
path: staging
test:
permissions:
checks: write
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Test with Maven
run: mvn --batch-mode --fail-at-end test
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/target/surefire-reports/TEST-*.xml'
integrationtest:
permissions:
checks: write
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: maven
- uses: ankane/setup-elasticsearch@v1
with:
elasticsearch-version: 8
config: |
http.port: 9200
- name: Clear existing docker image cache
shell: bash
run: docker image prune -af
- name: Integration Test with Maven
run: mvn clean install test-compile failsafe:integration-test failsafe:verify --batch-mode --fail-at-end
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/target/failsafe-reports/TEST-*.xml'
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
# - name: Update dependency graph
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
53 changes: 30 additions & 23 deletions docker-compose-integrationtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@

version: "3.7"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.2.0
hostname: elasticsearch-cf
networks:
- channelfinder-net
environment:
cluster.name: channelfinder
bootstrap.memory_lock: "true"
discovery.type: single-node
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
xpack.security.enabled: "false"
volumes:
- channelfinder-es-data:/usr/share/elasticsearch/data
healthcheck:
test: curl -f http://elasticsearch-cf:9200/_cluster/health
interval: 30s
timeout: 60s
retries: 5

channelfinder:
build:
context: .
Expand All @@ -29,36 +48,24 @@ services:
- 8080:8080
- 8443:8443
depends_on:
elasticsearch:
condition: service_healthy
links:
- elasticsearch
environment:
elasticsearch.network.host: elasticsearch-cf
elasticsearch.http.port: 9200
ldap.enabled: "false"
embedded_ldap.enabled: "false"
demo_auth.enabled: "true"
command: >
/bin/bash -c "
until curl -s -f http://elasticsearch-cf:9200/_cluster/health; do
echo Waiting for Elasticsearch;
sleep 1;
done;
java -jar /channelfinder/ChannelFinder-*.jar --spring.config.name=application"
command: "java -jar /channelfinder/ChannelFinder-*.jar --spring.config.name=application"
restart: on-failure
healthcheck:
test: curl -s -f http://channelfinder:8080/ChannelFinder
interval: 30s
timeout: 60s
retries: 5

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.2.0
hostname: elasticsearch-cf
networks:
- channelfinder-net
ports:
- 9201:9200
- 9301:9300
environment:
cluster.name: channelfinder
bootstrap.memory_lock: "true"
discovery.type: single-node
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
xpack.security.enabled: "false"
volumes:
- channelfinder-es-data:/usr/share/elasticsearch/data

volumes:
channelfinder-es-data:
Expand Down
60 changes: 33 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>

<artifactId>ChannelFinder</artifactId>
<groupId>org.phoebus</groupId>
<version>4.7.3-SNAPSHOT</version>
<name>ChannelFinder Service</name>

<description>A RESTful directory services for a list channels</description>
<url>https://channelfinder.readthedocs.io/</url>
<description>A RESTful directory services for a list channels</description>
<url>https://channelfinder.readthedocs.io/</url>

<licenses>
<license>
<name>Eclipse Public License 1.0</name>
<url>https://www.eclipse.org/legal/epl-v10.html</url>
</license>
</licenses>
<licenses>
<license>
<name>Eclipse Public License 1.0</name>
<url>https://www.eclipse.org/legal/epl-v10.html</url>
</license>
</licenses>

<scm>
<url>https://github.com/ChannelFinder/ChannelFinderService</url>
<connection>scm:git:https://github.com/ChannelFinder/ChannelFinderService</connection>
<developerConnection>scm:git:https://github.com/ChannelFinder/ChannelFinderService</developerConnection>
<tag>HEAD</tag>
</scm>
<scm>
<url>https://github.com/ChannelFinder/ChannelFinderService</url>
<connection>scm:git:https://github.com/ChannelFinder/ChannelFinderService</connection>
<developerConnection>scm:git:https://github.com/ChannelFinder/ChannelFinderService</developerConnection>
<tag>HEAD</tag>
</scm>


<developers>
Expand Down Expand Up @@ -202,6 +202,22 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<skipTests>false</skipTests>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand All @@ -220,7 +236,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>3.11.0</version>
<configuration>
<source>11</source>
<target>11</target>
Expand All @@ -230,7 +246,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
Expand All @@ -241,16 +257,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/phoebus/channelfinder/ElasticConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import co.elastic.clients.elasticsearch.indices.CreateIndexRequest;
import co.elastic.clients.elasticsearch.indices.CreateIndexResponse;
import co.elastic.clients.elasticsearch.indices.DeleteIndexRequest;
import co.elastic.clients.elasticsearch.indices.ExistsRequest;
import co.elastic.clients.transport.endpoints.BooleanResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -147,9 +148,8 @@ public void contextDestroyed(ServletContextEvent sce) {
indexClient.shutdown();
}


/**
* Create the olog indices and templates if they don't exist
* Create the indices and templates if they don't exist
* @param client
*/
void elasticIndexValidation(ElasticsearchClient client) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/phoebus/channelfinder/TagRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
Expand All @@ -15,8 +16,10 @@
import co.elastic.clients.elasticsearch._types.Result;
import co.elastic.clients.elasticsearch._types.SortOptions;
import co.elastic.clients.elasticsearch._types.query_dsl.IdsQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import co.elastic.clients.elasticsearch.core.BulkRequest;
import co.elastic.clients.elasticsearch.core.BulkResponse;
import co.elastic.clients.elasticsearch.core.DeleteByQueryRequest;
import co.elastic.clients.elasticsearch.core.DeleteResponse;
import co.elastic.clients.elasticsearch.core.ExistsRequest;
import co.elastic.clients.elasticsearch.core.GetResponse;
Expand Down Expand Up @@ -310,6 +313,7 @@ public long count() {
@Override
public void deleteById(String tagName) {
try {

DeleteResponse response = client
.delete(i -> i.index(esService.getES_TAG_INDEX()).id(tagName).refresh(Refresh.True));
// verify the deletion of the tag
Expand Down Expand Up @@ -348,7 +352,6 @@ public void deleteById(String tagName) {
logger.log(Level.SEVERE, () -> item.error().reason());
}
}
} else {
}
} catch (IOException e) {
String message = MessageFormat.format(TextUtil.FAILED_TO_DELETE_TAG, tagName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class PopulateService {
public static ObjectMapper mapper = new ObjectMapper();


static int index = 0;
static int index;

static List<Integer> tokens_1000 = new ArrayList<>();
static List<Integer> tokens_500 = new ArrayList<>();
Expand Down Expand Up @@ -155,7 +155,7 @@ public synchronized void cleanupDB() {
try {
BulkResponse result = client.bulk(br.refresh(Refresh.True).build());
if (result.errors()) {
logger.log(Level.SEVERE, "Bulk had errors");
logger.log(Level.SEVERE, "CleanupDb Bulk had errors");
for (BulkResponseItem item : result.items()) {
if (item.error() != null) {
logger.log(Level.SEVERE, () -> item.error().reason());
Expand Down Expand Up @@ -184,15 +184,15 @@ public synchronized void createDB() {
try {
finalResult.add(insertSRCell(cell));
} catch (Exception e) {
e.printStackTrace();
logger.log(Level.WARNING, e.getMessage(), e);
}
}
for (int i = 1; i <= numberOfCells; i++) {
String cell = String.format("%03d", i);
try {
finalResult.add(insertBOCell(cell));
} catch (Exception e) {
e.printStackTrace();
logger.log(Level.WARNING, e.getMessage(), e);
}
}
final long time = System.currentTimeMillis() - start;
Expand All @@ -206,25 +206,25 @@ public synchronized void createDB() {

BulkRequest.Builder br = new BulkRequest.Builder();
for (Property property : prop_list) {
br.operations(op -> op.index(index -> index.index(esService.getES_PROPERTY_INDEX()).id(property.getName()).document(property)));
br.operations(op -> op.index(bIndex -> bIndex.index(esService.getES_PROPERTY_INDEX()).id(property.getName()).document(property)));
}
for (Tag tag : tag_list) {
br.operations(op -> op.index(index -> index.index(esService.getES_TAG_INDEX()).id(tag.getName()).document(tag)));
br.operations(op -> op.index(bIndex -> bIndex.index(esService.getES_TAG_INDEX()).id(tag.getName()).document(tag)));
}
br.refresh(Refresh.True);

try {
BulkResponse results = client.bulk(br.build());
if (results.errors()) {
logger.log(Level.SEVERE, "Bulk had errors");
logger.log(Level.SEVERE, "CreateDB Bulk had errors");
for (BulkResponseItem item : results.items()) {
if (item.error() != null) {
logger.log(Level.SEVERE, () -> item.error().reason());
}
}
}
} catch (IOException e) {
e.printStackTrace();
logger.log(Level.WARNING, "CreateDB Bulk operation failed.", e);
}
logger.log(Level.INFO, "completed populating");
}
Expand Down Expand Up @@ -389,7 +389,7 @@ private boolean insertBOCell(String cell) throws Exception {
String execute = "|Execute: " + (System.currentTimeMillis() - start) + "|";
logger.log(Level.INFO, "Insterted BO cell " + cell + " " + prepare + " " + execute);
if (boosterResult.errors()) {
logger.log(Level.SEVERE, "Bulk had errors");
logger.log(Level.SEVERE, "insertBOCell Bulk had errors");
for (BulkResponseItem item : boosterResult.items()) {
if (item.error() != null) {
logger.log(Level.SEVERE, () -> item.error().reason());
Expand Down
Loading

0 comments on commit f0fdce2

Please sign in to comment.