Bash/Shell - Nested Variables for Dynamic UDeploy Property - urbancode

I need a little help with a process we're trying to build that should be able to react dynamically.
The process goes a little something like this.
User will submit a process request against an environment, submitting an array of string values as a runtime value. The process will take these in, as an array in bash, and loop through them, checking them against a predefined string list for validity. Upon finding they are valid, reacting differently based off of which values are in the string.
Example:
User submits a process request with values "abc", "bcd", "cde", "def"
Values "abc", "bcd", and "def" are valid.
We do a bit of manipulation to make them usable:
echo ${p:inputArray}
inputArray="${p:inputArray}"
inputArray=${inputArray//]/}
inputArray=${inputArray//[/}
inputArray=${inputArray//,/}
inputArray=( "${inputArray[#],,}" )
Then loop through each value and react:
for inputValue in $inputArray; do
if [[ "${validInputArray[#]}" =~ "${inputValue}" ]]; then
// Check if value is the outlier case "A"
// Or if the value is normal (but multiple) case "B"
// If case "B" then we'll build a variable for it
// It should be something like ${p:environment/$inputValue.action}
This, ideally, would give me the value of ${p:environment/abc.action} for example. But it does not. It gives me a string. I have no way to evaluate the dynamically created property request, as all properties are evaluated at initialization and not on the fly.
We can handle it via a "case" method - but it's a bit ugly, and will only get uglier as our number of valid inputs grow.

Instead of sending it an array of values, you can configure UCD to prompt them for specific values. You can do this on the application process. That way, when the user kicks off the deployment, there is no guessing on the validity of the input.
On the process page of the application, click on the Application Process Properties link
From there, you can configure it to require a certain pattern (checked via regex), or explicit values from a drop down, raw text, dateTime, etc. Here, I've configured a property with a multi-select to allow specific JVM maximum heap values. By limiting this to specific values, you can avoid typos and failed deployments.
Once configured, when you launch your process, you are presented with the property in the interface:

Related

Jmeter extraction and using on If Controller

Is there's a way I can simulate this scenario, Example If there's a value extracted it will execute "TC1" Request, but If I extracted blank value it will execute "TC2".
The easiest method which provides maximum flexibility is using Switch Controller
As per documentation:
If the switch value is out of range, it will run the zeroth element, which therefore acts as the default for the numeric case. It also runs the zeroth element if the value is the empty string.
If the value is non-numeric (and non-empty), then the Switch Controller looks for the element with the same name (case is significant). If none of the names match, then the element named "default" (case not significant) is selected. If there is no default, then no element is selected, and the controller will not run anything.
So given the following Test Plan structure:
Switch Controller, switch value - your extracted variable
Simple Controller with an arbitrary name
TC2 sampler(s) as child(ren) of the Switch Controller
Simple Controller with name default
TC1 sampler(s) as chidr(ren) of the Switch Controller
Demo:
More information: Running JMeter Samplers with Defined Percentage Probability

Make beam/dataflow Create.of(List<String>) node emit exactly the number of elements in the list

My beam/dataflow job starts with a single static entry passed in like this:
Pipeline p = Pipeline.create(options);
PCollection<String> initValue = p.apply(Create.of("MyStringValue"));
However when I run it (on DataflowRunner), the Create node produced by that statement emits multiple values. The longer I wait, the more times it emits the single value:
This doesn't appear to be an artefact as later in the pipeline I get duplicate/triplicate/.. elements. Beam also logs a warning:
Can't verify serialized elements of type BoundedSource have well defined equals method. This may produce incorrect results on some PipelineRunner
How do I make my Create.of with one value emit just one value to the pipeline?
Do I need to attach an equals method or point it towards the equals method for String values (if so, how)!?

What is really happening when using variables?

I have a really basic question about something that I've never paid much attention to until now:
I noticed that when creating a function (in JS or Python) that uses a variable from the outer scope, the function is not defined using the value of the variable but rather the variable itself. So if I change the value of the variable the function will use the new value.
This is what I mean
let a = 10;
function printA(){
console.log(a);
}
printA(); // => 10
a = 20;
printA(); // => 20
a = 10
def printA():
print(a)
printA() # => 10
a = 20
printA() # => 20
I thought this was only going to work of objects because of the way you can modify an object inside a function but not primitive variables because there's no way to change their value without reasigning them. I guess this is a different story.
What I'm trying to understand is: when typing a variable name is typing its memory address what I'm really doing? Does this happen with all languages?
when I create a function like printA() that uses a variable that is not an argument, is the variable bound forever to the function by its address?
The variable a is "captured" by the function. The specifics of how that happens are usually implementation details and may result in the compiler/interpreter producing code that doesn't much resemble the original.
For instance, in C# (I know, not one of the languages you mentioned, but it's the one I'm most familiar with), the compiler will create a separate hidden class which actually contains fields for the variables that are captured by a lambda or nested function. It then accesses these fields rather than plain variables.
by its address
Variables don't typically have an address. For instance, every time you call a method, it will typically have an "activation record" of some kind created, that will typically contain its variables. But note that these records are not at some fixed location, which is how you can have parallel execution of methods, recursion, etc, without interference. (Some older BASICs did have fixed activation records, which is why they didn't allow for recursion). These activation records may typically be placed on some kind of stack.
But as I say, for captured variables, the compiler will typically need to do even more so that those variables aren't just stored in an activation record, and so that their lifetime is no longer tied to a single call.

How do I keep a variable consistant even after seperate play sessions?

I have a variable area which stores a number.
When the app is restarted, it is reset back to it's original value. How can I keep area persistent after being closed?
I'm using Flash CS6 for Android
You'll have to save the variable. There's multiple ways to do this but using a SharedObject is the easiest IMO.
First thing is you don't actually create a new instance of the SharedObject class, you instead call the static function getLocal and this sets your variable. So somewhere near the start of your program you'll want something like this:
var gameSave:SharedObject = SharedObject.getLocal("gameSave");
This either creates a new locally persistent shared object if one does not exist or it grabs the one with the same initialized name ("gameSave") on your computer. This way you can access the saved variables across multiple playthroughs.
Now to save a variable you simply use the dataObject on the shared object and write values to it, then you call the function flush when you're done writing values to immediately save the shared object to your computer.
So saving your area value would look something like this:
gameSave.data.area = Main.area;
gameSave.flush();
After that you'll want to set the area value to whatever the saved value is when your game launches:
if (gameSave.data.area !== undefined) Main.area = gameSave.data.area;
We check if the value is undefined because it might not exist yet if you're playing the game for the first time and the area hasn't been saved yet.
Last thing in case you want to expand the scope of this and save more values: you can only write specific values to the shared object. The way I understand it is you can only write certain class types and primitives. If you try to write anything that's not a primitive or the exception classes, it'll automatically convert that item to an Object and it more or less becomes useless. The classes that it can accept that you'll probably use the most are: int, uint, Number, String, Boolean, Object, and Array. It has a few others like ByteArray and XML, but you'll either not use those at all or not use them very frequently. If you want to save any other class type you'll have to add that functionality yourself.

Reading RawRequest JSON parameter value in SoapUI changes its value

I'm trying to transfer parameter from RawRequest using SoapUI but when reading it, value changes.
The parameter is request ID (which is unique for every test), it is requested by every test case from Custom Properties, where it is stored as follows:
${=((System.currentTimeMillis().toString()).subSequence(4, (System.currentTimeMillis().toString()).length())).replaceFirst("0", "")}
Above generates number like this for example:17879164.
The problem starts, when I'm trying to transfer it using either in build in feature or Groovy script. Both read parameter incorrectly:
Following is how the parameter presents in RawRequest window:
This is how it is read in Transfer window in SoapUI:
And finally, how it is read by Groovy script:
Can any one explain, why this value despite being shown in SoapUI RawRequest window as 17879164 is then read as 17879178 using two different methods?
I think the clue might be, that when I'm using "flat number" as reqId and not the generated one, both methods work fine and return correct number. But in this case when it is RawRequest, I understand that it is set once and for all, so what is show in the window and what is being read, should be the same.
What you are seeing is a "feature" in SoapUI. Your transfer step will transfer the code, which will then get evaluated again, resulting in a different value.
What you need to do is:
Create a test case property.
Set the property from test case setup script to a value. So in your case, something like testCase.setPropertyValue("your_property", ((System.currentTimeMillis().toString()).subSequence(4, (System.currentTimeMillis().toString()).length())).replaceFirst("0", ""))
Anywhere in your test refer to the test case property ${#TestCase#your_property}... which is a fixed value at this point, so will be always the same.