Skip to content

Commit

Permalink
Add message store test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
pamod committed Dec 3, 2023
1 parent 77fc132 commit 270d410
Show file tree
Hide file tree
Showing 12 changed files with 694 additions and 4 deletions.
8 changes: 6 additions & 2 deletions modules/integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
<mkdir dir="target/test_repos/axis2Server" />
<mkdir dir="target/test_repos/axis2Client" />
<mkdir dir="target/test_repos/synapse" />
<mkdir dir="target/test_repos/synapse" />
<mkdir dir="target/test_repos/synapse/modules" />
<mkdir dir="target/test_repos/synapse/conf" />
<mkdir dir="target/test_repos/synapse/samples" />
<mkdir dir="target/test_repos/axis2Server/services" />
<mkdir dir="target/test_repos/axis2Server/modules" />
<mkdir dir="target/test_repos/axis2Server/conf" />
Expand All @@ -81,7 +81,11 @@
<include name="*.xml" />
</fileset>
</copy>

<copy todir="target/test_repos/synapse/samples">
<fileset dir="src/test/resources/extras">
<include name="*_altered_msmp.xml" />
</fileset>
</copy>
<!--<copy file="src/test/resources/trust.jks"-->
<!--tofile="target/test_repos/synapse/conf/trust.jks" />-->
<!--<copy file="src/test/resources/identity.jks"-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,18 @@ private void initData() throws Exception {

//client
String dbName = "synapsedb";
String createTableQuery = "CREATE table company(name varchar(10), id varchar(10), price double)";
String createCompanyTableQuery = "CREATE table company(name varchar(10), id varchar(10), price double)";
final String createJDBCMessageStoreQuery = "CREATE TABLE jdbc_message_store" +
"(indexId INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY(Start with 1, Increment by 1)," +
"msg_id VARCHAR(200) NOT NULL,message BLOB NOT NULL)";
final String createResequenceMessageStoreQuery = "CREATE TABLE tbl_resequence" +
"(indexId INTEGER GENERATED ALWAYS AS IDENTITY(Start with 1, Increment by 1) PRIMARY KEY," +
"msg_id VARCHAR(200) NOT NULL UNIQUE," +
"seq_id INTEGER NOT NULL UNIQUE," +
"message BLOB NOT NULL)";
final String createLastProcessedIdTblQuery = "CREATE TABLE tbl_lastprocessid" +
"(statement VARCHAR(20) PRIMARY KEY,seq_id INTEGER NOT NULL UNIQUE)";

String connectionURL = "jdbc:derby://localhost:1527/" + dbName + ";create=true";

java.util.Properties props = new java.util.Properties();
Expand All @@ -96,7 +107,10 @@ private void initData() throws Exception {
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
conn = DriverManager.getConnection(connectionURL, props);
Statement s = conn.createStatement();
s.execute(createTableQuery);
s.execute(createCompanyTableQuery);
s.execute(createJDBCMessageStoreQuery);
s.execute(createResequenceMessageStoreQuery);
s.execute(createLastProcessedIdTblQuery);
s.execute("INSERT into company values ('IBM','c1',0.0)");
s.execute(" INSERT into company values ('SUN','c2',0.0)");
s.execute(" INSERT into company values ('MSFT','c3',0.0)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,36 @@ protected SynapseTestCase(int sampleId) {
loadConfiguration();
}

/**
* Apply configuration values to message store XML.
*
* @param synapseRepoPath path to the synapse XML repository.
* @param axis2BlockingConfigPath path to axis2 blocking client.
*/
private void applyMessageStoreConfigurationToFile(OMElement synapseRepoPath, OMElement axis2BlockingConfigPath,
OMElement config) {
try {
if (null != synapseRepoPath && null != axis2BlockingConfigPath) {
String currentDir = SynapseTestUtils.getCurrentDir();
String sampleFilePath = SynapseTestUtils.getRequiredParameter(config.getFirstChildWithName
(new QName(SampleConfigConstants.TAG_SYNAPSE_CONF)),
SampleConfigConstants.TAG_SYNAPSE_CONF_XML);
String normalizeFilePath = FilenameUtils.normalize(currentDir + sampleFilePath);
File synapseSampleFile = new File(normalizeFilePath);
String synapseXml = FileUtils.readFileToString(synapseSampleFile);
String modifiedSynapseAxis2 = SynapseTestUtils.replace(synapseXml, "${AXIS2_REPO}",
FilenameUtils.normalize(currentDir + synapseRepoPath.getText()));
String modifiedAxis2Blocking = SynapseTestUtils.replace(modifiedSynapseAxis2, "${AXIS2_CONFIG}",
FilenameUtils.normalize(currentDir + axis2BlockingConfigPath.getText()));
FileUtils.writeStringToFile(synapseSampleFile, modifiedAxis2Blocking);
}
} catch (IOException e) {
String message = "Error occurred while reading the sample configuration";
log.error(message, e);
fail(message);
}
}

private void loadConfiguration() {
// Parse the sample descriptor
OMElement sampleConfig = loadDescriptorInfoFile();
Expand All @@ -91,6 +121,17 @@ private void loadConfiguration() {
this.sampleName = sampleNameElt.getText();
}

// Load synapse repo name and axis2blocking client, needed for message stores
OMElement synapseConfigElement =
sampleConfig.getFirstChildWithName(new QName(SampleConfigConstants.TAG_SYNAPSE_CONF));
OMElement synapseRepoPath = synapseConfigElement.getFirstChildWithName(
new QName(SampleConfigConstants.TAG_SYNAPSE_CONF_AXIS2_REPO));
OMElement axis2BlockingConfigPath = synapseConfigElement.getFirstChildWithName(
new QName(SampleConfigConstants.TAG_AXIS2_BLOCKING_CONFIG));

//Apply the configurations to the file
applyMessageStoreConfigurationToFile(synapseRepoPath, axis2BlockingConfigPath, sampleConfig);

// Load Synapse, backend server and client configurations
synapseController = initSynapseConfigInfo(sampleConfig);
backendServerControllers = initBackEndServersConfigInfo(sampleConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ private static void populateSamplesMap() {
sampleClassRepo.put("451", Sample451.class);
sampleClassRepo.put("452", Sample452.class);
sampleClassRepo.put("460", Sample460.class);
sampleClassRepo.put("706", Sample706.class);
sampleClassRepo.put("707", Sample707.class);

sampleClassRepo.put("800", Sample800.class);
sampleClassRepo.put("10001", Sample10001.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class SampleConfigConstants {

public static final String TAG_BE_SERVER_CONF_AXIS2_REPO = "axis2Repo";
public static final String TAG_BE_SERVER_CONF_AXIS2_XML = "axis2Xml";
public static final String TAG_AXIS2_BLOCKING_CONFIG = "axis2BlockingXml";
public static final String TAG_BE_SERVER_CONF_AXIS2_HTTP_PORT = "httpPort";
public static final String TAG_BE_SERVER_CONF_AXIS2_HTTPS_PORT = "httpsPort";
public static final String TAG_BE_SERVER_CONF_AXIS2_COUNTER_ENABLED = "counterEnabled";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.synapse.samples.framework.tests.advanced;

import org.apache.synapse.samples.framework.SampleClientResult;
import org.apache.synapse.samples.framework.SynapseTestCase;
import org.apache.synapse.samples.framework.clients.StockQuoteSampleClient;

public class Sample706 extends SynapseTestCase {
public Sample706() {
super(706);
}

public void testJDBCMessageStore() throws InterruptedException {
String trpUrl = "http://localhost:8280/";
StockQuoteSampleClient client = getStockQuoteClient();
log.info("Running test: Introduction to JDBC message store ");
SampleClientResult result = client.placeOrder(null, trpUrl, null, "WSO2-1");
assertTrue("Client received response successfully ", result.responseReceived());
Thread.sleep(7000);
assertEquals(1, getAxis2Server().getMessageCount("SimpleStockQuoteService", "placeOrder"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.synapse.samples.framework.tests.advanced;

import org.apache.synapse.samples.framework.SynapseTestCase;
import org.apache.synapse.samples.framework.clients.StockQuoteSampleClient;

public class Sample707 extends SynapseTestCase {
public Sample707() {
super(707);
}

public void testResequenceMessageStore() throws InterruptedException {
String trpUrl = "http://localhost:8280/";
StockQuoteSampleClient client = getStockQuoteClient();
log.info("Running test: Introduction to the script mediator using js scripts ");
client.placeOrder(null, trpUrl, null, "WSO2-4");
client.placeOrder(null, trpUrl, null, "WSO2-2");
client.placeOrder(null, trpUrl, null, "WSO2-3");
client.placeOrder(null, trpUrl, null, "WSO2-1");
Thread.sleep(10000);
assertEquals(4, getAxis2Server().getMessageCount("SimpleStockQuoteService", "placeOrder"));

}
}
Loading

0 comments on commit 270d410

Please sign in to comment.