Skip to content

Commit

Permalink
added workflow for testing a broker in container
Browse files Browse the repository at this point in the history
  • Loading branch information
NehaSelvan1512 committed Sep 28, 2023
1 parent f70e933 commit a13c18d
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/mqttClientTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Polypheny-DB MQTT Client Test

on:
push: { branches: mqtt-interface }

jobs:
build:
runs-on: ubuntu-latest
name: MQTT Client Tests (Java 17)
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 17
- name: Set env variable
run: |
echo "POLYPHENY_HOME=$GITHUB_WORKSPACE" >> $GITHUB_ENV
- name: Create folders for certs
run: |
mkdir $POLYPHENY_HOME/.polypheny
mkdir $POLYPHENY_HOME/.polypheny/certs
- name: Start Mosquitto broker in docker container
uses: namoshek/mosquitto-github-action@v1
with:
version: '5'
ports: '1883:1883'
container-name: 'mqttBroker'

- name: Assemble
uses: nick-invision/retry@v2
with:
max_attempts: 2
timeout_minutes: 60
command: ./gradlew assemble

- name: Build Plugins
uses: nick-invision/retry@v2
with:
max_attempts: 1
timeout_minutes: 60
command: ./gradlew assemblePlugins

- name: Execute MQTT client tests
uses: nick-invision/retry@v2
with:
max_attempts: 1
timeout_minutes: 30
command: ./gradlew mqttTests
10 changes: 10 additions & 0 deletions plugins/mqtt-stream/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ sourceSets {
}
}

task mqttTests(type: Test) {
description = 'Runs MQTT client tests.'
group = 'verification'
useJUnit {
includeCategories 'org.polypheny.db.mqtt.MqttClientBrokerTest'
}
shouldRunAfter(tasks.named('test'))
}
mqttTests.dependsOn(testClasses)

compileJava {
dependsOn(":config:processResources")
dependsOn(":core:processResources")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright 2019-2023 The Polypheny Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.polypheny.db.mqtt;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.polypheny.db.TestHelper;
import org.polypheny.db.iface.QueryInterface;
import org.polypheny.db.iface.QueryInterfaceManager;
import org.polypheny.db.mqtt.MqttStreamPlugin.MqttStreamClient;
import org.polypheny.db.transaction.Transaction;
import org.polypheny.db.transaction.TransactionManager;

public class MqttClientBrokerTest {


static TransactionManager transactionManager;
static Transaction transaction;
static Map<String, String> initialSettings = new HashMap<>();
static Map<String, String> changedSettings = new HashMap<>();
static MqttStreamClient client;

@BeforeClass
public static void init() {
TestHelper testHelper = TestHelper.getInstance();
transactionManager = testHelper.getTransactionManager();
transaction = testHelper.getTransaction();
initialSettings.clear();
initialSettings.put( "brokerAddress", "1883" );
initialSettings.put( "brokerPort", "1883" );
initialSettings.put( "commonCollectionName", "testCollection" );
initialSettings.put( "commonCollection", "true" );
initialSettings.put( "namespace", "testNamespace" );
initialSettings.put( "namespaceType", "DOCUMENT" );
initialSettings.put( "topics", "button" );
initialSettings.put( "Tsl/SslConnection", "false" );
initialSettings.put( "filterQuery", "" );

QueryInterface iface = QueryInterfaceManager.getInstance().getQueryInterface( "mqtt" );

client = new MqttStreamClient(
transactionManager,
null,
iface.getQueryInterfaceId(),
iface.getUniqueName(),
initialSettings );

}

/*
@Before
public void resetSettings() {
initialSettings.clear();
initialSettings.put( "brokerAddress", "1883" );
initialSettings.put( "brokerPort", "1883" );
initialSettings.put( "commonCollectionName", "testCollection" );
initialSettings.put( "commonCollection", "true" );
initialSettings.put( "namespace", "testNamespace" );
initialSettings.put( "namespaceType", "DOCUMENT" );
initialSettings.put( "topics", "" );
initialSettings.put( "Tsl/SslConnection", "false" );
initialSettings.put( "filterQuery", "" );
QueryInterface iface = QueryInterfaceManager.getInstance().getQueryInterface( "mqtt" );
client = new MqttStreamClient(
transactionManager,
null,
iface.getQueryInterfaceId(),
iface.getUniqueName(),
initialSettings );
changedSettings.clear();
changedSettings.put( "commonCollectionName", "testCollection" );
changedSettings.put( "commonCollection", "true" );
changedSettings.put( "namespace", "testNamespace" );
changedSettings.put( "topics", "" );
changedSettings.put( "filterQuery", "" );
}
*/

@Test
public void connectionTest() {
Map<String, AtomicLong> topicsMap = client.getTopicsMap();
assertEquals( 1, topicsMap.size() );
assertEquals( 0, topicsMap.get( "button" ) );
}




}

0 comments on commit a13c18d

Please sign in to comment.