Apache Beam TextIO.read().from() does not interpret escaped special character in filepattern - apache-beam

Environment
Java SDK 2.33.0
Setup
$ mkdir -p /tmp/beam
$ echo "test" >> "/tmp/beam/test*.txt"
Test pipeline
public class PipelineTest {
#Test
public void test() {
Pipeline p = TestPipeline.create().enableAbandonedNodeEnforcement(false);
String filename = "/tmp/beam/test\\*.txt";
PCollection<String> input = p.apply(TextIO.read().from(filename));
PAssert.that(input).containsInAnyOrder("test");
p.run();
}
}
This test fails with below messages.
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 10.66 s <<< FAILURE! - in PipelineTest
[ERROR] test Time elapsed: 10.645 s <<< ERROR!
org.apache.beam.sdk.Pipeline$PipelineExecutionException: java.io.FileNotFoundException: No files matched spec: /tmp/beam/test\*.txt
at PipelineTest.test(PipelineTest.java:28)
Caused by: java.io.FileNotFoundException: No files matched spec: /tmp/beam/test\*.txt
How can I read files that contain asterisks or other special characters?

For now you'll simply have to rename such files. I've filed https://issues.apache.org/jira/browse/BEAM-13231

Related

powershell query to extract specific string from text file and export that in excel

need to extract the string " VQ_UHC_GovtPrograms_Sales_LeadCapture_Mandarin_Callback#VQ-switch" from below log file" when the condition is "is not found on Switch" error is found in the log.
=================================================
So the output should be:
QueueName Date
==================================================
2022-08-07 20:36:41.534 ERROR 11100 --- [com.test.PCT.invoker.default] split.logs.queue-stat : Stat request failed for Stat Server: statserver-test-rrr_1a StatName: 'AverAbandCallTime' QueueName: 'VQ_UHC_GovtPrograms_Sales_LeadCapture_Mandarin_Callback#VQ-switch' Reason: 'Queue 'VQ_UHC_GovtPrograms_Sales_LeadCapture_Mandarin_Callback' is not found on Switch 'VQ-switch' (Tenant 'Environment')'
=======

How can I mark some ScalaTests so that they only execute when invoked explicitly

I'm new to SBT and scalatest but am wondering how I get some of my org.scalatest._ tests to only execute "on demand".
In SBT I can invoke all of the Unit Tests like sbt:Sprout> test, or all of the IntegrationTests like sbt:Sprout> it:test. I need a way to annotate the tests that allows an sbt:Sprout test invocation to skip them but with some other invocation executes ONLY these tests. Scalatest docs speak of some sbt:Sprout> test-only *RedSuite invocation to allow me to "Categorize" my tests, but its not clear how to leverage that so they DON'T run as Unit Tests. org.scalatest.Tags alone do not get it off the "default" of getting executed when sbt:Sprout> test. I need these to be ignored unless invoked explicitly.
Is this use case possible in ScalaTest through SBT?
You can specify tag names of tests to include or exclude from a run. To specify tags to include, use -n followed by a list of tag names to include. Similarly, to specify tags to exclude, use -l followed by a list of tag names to exclude
(please look here for more info in the official documents).
For example:
package com.test
import org.scalatest.FlatSpec
import org.scalatest.Tag
object IncludeTest extends Tag("com.tags.Include")
object ExcludeTest extends Tag("com.tags.Exclude")
class TestSuite extends FlatSpec {
"Test1" taggedAs(IncludeTest) in {
val sum = 1 + 1
assert(sum === 2)
}
"Test2" taggedAs(ExcludeTest) in {
val minus = 2 - 1
assert(minus === 1)
}
}
To include IncludeTest and exclude ExcludeTest tag, you should do:
test-only org.* -- -n com.tags.Include -l com.tags.Exclude
assume assertion specified inside a fixture-context object could be used to implement conditional-ignore semantics dependant on environmental flag. For example, consider the following IfIgnored fixture
trait IfIgnored extends Assertions {
assume(System.getenv("runIgnoredTest").toBoolean, "!!! TEST IGNORED !!!")
}
which can be instantiated like so
it should "not say goodbye" in new IfIgnored {
Hello.greeting shouldNot be ("goodbye")
}
Now if we define the following settings in build.sbt
Test / fork := true,
Test / envVars := Map("runIgnoredTest" -> "false")
and the following tests
class HelloSpec extends FlatSpec with Matchers {
"The Hello object" should "say hello" in {
Hello.greeting shouldEqual "hello"
}
it should "not say goodbye" in new IfIgnored {
Hello.greeting shouldNot be ("goodbye")
}
it should "not say live long and prosper" in new IfIgnored {
Hello.greeting shouldNot be ("live long and prosper")
}
}
then executing sbt test should output
[info] HelloSpec:
[info] The Hello object
[info] - should say hello
[info] - should not say goodbye !!! CANCELED !!!
[info] scala.Predef.augmentString(java.lang.System.getenv("runIgnoredTest")).toBoolean was false !!! TEST IGNORED !!! (HelloSpec.scala:6)
[info] - should not say live long and prosper !!! CANCELED !!!
[info] scala.Predef.augmentString(java.lang.System.getenv("runIgnoredTest")).toBoolean was false !!! TEST IGNORED !!! (HelloSpec.scala:6)
[info] Run completed in 2 seconds, 389 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 2, ignored 0, pending 0
[info] All tests passed.
where we see only should say hello ran whilst the rest were ignored.
To execute only ignored tests we could define the following custom command testOnlyIgnored:
commands += Command.command("testOnlyIgnored") { state =>
val ignoredTests = List(
""""should not say goodbye"""",
""""should not say live long and prosper""""
).mkString("-z ", " -z ", "")
"""set Test / envVars := Map("runIgnoredTest" -> "true")""" ::
s"""testOnly -- $ignoredTests""" :: state
}
Note how we are making use of -z runner argument to run particular tests, for example,
testOnly -- -z "should not say goodbye" -z "should not say live long and prosper"
Also note how we are manually adding test names to ignoredTests. Now executing sbt testOnlyIgnored should output
[info] HelloSpec:
[info] The Hello object
[info] - should not say goodbye
[info] - should not say live long and prosper
[info] Run completed in 2 seconds, 298 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
where we see should say hello was not run whilst all the ignored tests ran.
If we drop the requirement of having to run ignored tests separately, then we can use provided ignore annotation like so
ignore should "not say goodbye" in {
Hello.greeting shouldNot be ("goodbye")
}
which on sbt test outputs
[info] HelloSpec:
[info] The Hello object
[info] - should say hello
[info] - should not say goodbye !!! IGNORED !!!
[info] - should not say live long and prosper !!! IGNORED !!!
[info] Run completed in 2 seconds, 750 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 2, pending 0

How to manipulate variable in Jenkins pipeline

been trying several trial and errors on where or how to cut the string in the variable and assign to a new variable to be used by jenkins stage. Normally just removing -TEST Jenkins pipeline indicated below:
properties([
[$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false],
parameters([choice(choices: ['SQA-ENV-CLONE', 'DEV-ENV-CLONE'],
description: 'Select the ENV', name: 'ENV')])])
pipeline {
agent any
stages {
stage('VALIDATE ENVIRONMENT') {
def ACTIVE = sh(returnStdout: true, script: "echo $ENV | sed -e 's/-CLONE//g'")
steps {
echo 'Checking 1st the ${ACTIVE}'
}
}
}
}
Error I'm getting
Running in Durability level: MAX_SURVIVABILITY
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 6: Not a valid stage section definition: "def ACTIVE = sh(returnStdout: true, script: "echo $ENV | sed -e 's/-CLONE//g'")". Some extra configuration is required. # line 6, column 9.
stage('VALIDATE ENVIRONMENT') {
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:131)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:125)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:560)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:521)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:330)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE
Lets say I choose "DEV-ENV-CLONE" as the value I'm expecting to have a successful build with this output:
Checking 1st the DEV-ENV
You need move the def ACTIVE = sh(...) into pipeline step script, They are Groovy script, only can be wrapped by script step.
stage('VALIDATE ENVIRONMENT') {
steps {
script {
ACTIVE = sh(
returnStdout: true,
script: "echo $ENV | sed -e 's/-CLONE//g'"
).trim()
}
echo "Checking 1st the ${ACTIVE}"
}
}

How to create a task that prints command line arguments?

I'm finding the documentation at http://www.scala-sbt.org/0.13/docs/Input-Tasks.html utterly baffling. Can someone provide me with a complete example of a task/input task that takes a command line argument and does something with it e.g.:
sbt "greeting hello world"
and prints "hello world"
Following the document Input Tasks (with the main change to the name of the input task so it's greeting):
import sbt.complete.Parsers.spaceDelimited
val greeting = inputKey[Unit]("A demo input task.")
greeting := {
val args: Seq[String] = spaceDelimited("<arg>").parsed
args foreach println
}
With the above in build.sbt, you can call the input task from the console:
> greeting "hello world"
hello world
or from the command line:
➜ so-25596401 xsbt 'greeting "hello world"'
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to so-25596401 (in build file:/Users/jacek/sandbox/so-25596401/)
hello world
[success] Total time: 0 s, completed Sep 1, 2014 1:34:31 AM
Note the quotes that designate what is the single task/command with arguments.

Zend_Test_PHPUnit how to print exception/output?

How can I echo a html/xml output from a controller action in my test case?
Here is my testcase:
public function testCreateAccountIsASuccessfulRequest()
{
$this->dispatch('/v2/user/create-account');
$this->assertFalse($this->response->isException());
$this->assertNotRedirect();
}
Which prints this in commandline:
test# /usr/local/bin/phpunit --verbose Controllers_UserControllerTest.php
PHPUnit 3.6.10 by Sebastian Bergmann.
F
Time: 0 seconds, Memory: 12.50Mb
There was 1 failure:
1) Controllers_UserControllerTest::testCreateAccountIsASuccessfulRequest
Failed asserting that true is false.
/path/to/tests/Controllers/UserControllerTest.php:17
/usr/local/bin/phpunit:46
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
test#
I am not sure what is the actual exception. How to see it? Also, how can I see the actual output of the controller action? So HTML/XML it sends to browser?
God I am slow today:
public function testCreateAccountIsASuccessfulRequest()
{
$this->dispatch('/v2/user/create-account');
echo $this->getResponse()->getBody();
$this->assertFalse($this->response->isException());
$this->assertNotRedirect();
}