forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move integration tests for function upload/download to apache (apach…
…e#2061) This change add `function-worker` into the `PulsarClusterTestBase` to create a test base for functions related tests `PulsarFunctionsTestBase`. Move the existing upload/download tests to use it.
- Loading branch information
Showing
11 changed files
with
403 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env python | ||
# | ||
# 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. | ||
# | ||
|
||
## | ||
## Generate a yml from env.py | ||
## | ||
## ./gen-yml-from-env.py <template yml file> [<template yml file>] | ||
## | ||
|
||
import os, sys | ||
import yaml | ||
|
||
if len(sys.argv) < 2: | ||
print 'Usage: %s' % (sys.argv[0]) | ||
sys.exit(1) | ||
|
||
conf_files = sys.argv[1:] | ||
|
||
for conf_filename in conf_files: | ||
conf = yaml.load(open(conf_filename)) | ||
|
||
# update the config | ||
modified = False | ||
for k in sorted(os.environ.keys()): | ||
key_parts = k.split('_') | ||
v = os.environ[k] | ||
|
||
i = 0 | ||
conf_to_modify = conf | ||
while i < len(key_parts): | ||
key_part = key_parts[i] | ||
if not key_part in conf_to_modify: | ||
break | ||
|
||
if i == (len(key_parts) - 1): | ||
if key_part == 'workerPort': | ||
conf_to_modify[key_part] = int(v) | ||
else: | ||
conf_to_modify[key_part] = v | ||
|
||
modified = True | ||
else: | ||
conf_to_modify = conf_to_modify[key_part] | ||
i += 1 | ||
# Store back the updated config in the same file | ||
f = open(conf_filename , 'w') | ||
yaml.dump(conf, f, default_flow_style=False) | ||
f.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tests/docker-images/latest-version-image/conf/functions_worker.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
[program:functions-worker] | ||
autostart=false | ||
redirect_stderr=true | ||
stdout_logfile=/var/log/pulsar/functions_worker.log | ||
directory=/pulsar | ||
environment=PULSAR_MEM=-Xms128M | ||
command=/pulsar/bin/pulsar functions-worker | ||
|
31 changes: 31 additions & 0 deletions
31
tests/docker-images/latest-version-image/scripts/run-functions-worker.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# 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. | ||
# | ||
|
||
bin/apply-config-from-env.py conf/client.conf && \ | ||
bin/gen-yml-from-env.py conf/functions_worker.yml && \ | ||
bin/apply-config-from-env.py conf/pulsar_env.sh | ||
|
||
if [ -z "$NO_AUTOSTART" ]; then | ||
sed -i 's/autostart=.*/autostart=true/' /etc/supervisord/conf.d/functions_worker.conf | ||
fi | ||
|
||
bin/watch-znode.py -z $zookeeperServers -p /initialized-$clusterName -w | ||
exec /usr/bin/supervisord -c /etc/supervisord.conf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...on-tests-topologies/src/main/java/org/apache/pulsar/tests/containers/WorkerContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* 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.pulsar.tests.containers; | ||
|
||
/** | ||
* A pulsar container that runs functions worker. | ||
*/ | ||
public class WorkerContainer extends PulsarContainer<WorkerContainer> { | ||
|
||
public WorkerContainer(String clusterName, String hostname) { | ||
super( | ||
clusterName, hostname, hostname, "bin/run-functions-worker.sh", -1, BROKER_HTTP_PORT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...tics/src/test/java/org/apache/pulsar/tests/integration/functions/PulsarFunctionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* 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.pulsar.tests.integration.functions; | ||
|
||
import static org.testng.Assert.assertTrue; | ||
|
||
import com.google.common.io.Files; | ||
import java.io.File; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.pulsar.tests.containers.WorkerContainer; | ||
import org.apache.pulsar.tests.integration.functions.utils.UploadDownloadCommandGenerator; | ||
import org.apache.pulsar.tests.topologies.PulsarCluster; | ||
import org.testcontainers.containers.Container.ExecResult; | ||
import org.testng.annotations.Test; | ||
|
||
@Slf4j | ||
public class PulsarFunctionsTest extends PulsarFunctionsTestBase { | ||
|
||
@Test | ||
public String checkUpload() throws Exception { | ||
String bkPkgPath = String.format("%s/%s/%s", | ||
"tenant-" + randomName(8), | ||
"ns-" + randomName(8), | ||
"fn-" + randomName(8)); | ||
|
||
UploadDownloadCommandGenerator generator = UploadDownloadCommandGenerator.createUploader( | ||
PulsarCluster.ADMIN_SCRIPT, | ||
bkPkgPath); | ||
String actualCommand = generator.generateCommand(); | ||
|
||
log.info(actualCommand); | ||
|
||
String[] commands = { | ||
"sh", "-c", actualCommand | ||
}; | ||
ExecResult output = pulsarCluster.getAnyWorker().execCmd(commands); | ||
assertTrue(output.getStdout().contains("\"Uploaded successfully\"")); | ||
return bkPkgPath; | ||
} | ||
|
||
@Test | ||
public void checkDownload() throws Exception { | ||
String bkPkgPath = checkUpload(); | ||
String localPkgFile = "/tmp/checkdownload-" + randomName(16); | ||
|
||
UploadDownloadCommandGenerator generator = UploadDownloadCommandGenerator.createDownloader( | ||
localPkgFile, | ||
bkPkgPath); | ||
String actualCommand = generator.generateCommand(); | ||
|
||
log.info(actualCommand); | ||
|
||
String[] commands = { | ||
"sh", "-c", actualCommand | ||
}; | ||
WorkerContainer container = pulsarCluster.getAnyWorker(); | ||
ExecResult output = container.execCmd(commands); | ||
assertTrue(output.getStdout().contains("\"Downloaded successfully\"")); | ||
String[] diffCommand = { | ||
"diff", | ||
PulsarCluster.ADMIN_SCRIPT, | ||
localPkgFile | ||
}; | ||
output = container.execCmd(diffCommand); | ||
assertTrue(output.getStdout().isEmpty()); | ||
assertTrue(output.getStderr().isEmpty()); | ||
} | ||
|
||
} |
Oops, something went wrong.