eschumac

PersistentModelMap - quick solution for flexible runtime edits

Discussion created by eschumac on Mar 24, 2016
Latest reply on Mar 25, 2016 by Joel NeSmith

I thought I would share with everyone something I've done to solve a few needs:

 

  • Empower the QA automation engineer to define data without redeploying a virtual service
  • Create virtual services faster without a lot of data dependency during creation.
  • Share data across services running on the same VSE

 

The solution I used was the PersistentModelMap API. You can essentially store a value on the server that is available to any service at runtime. Further, there are restful services running on the VSE that allow you to add key pairs for your PersistentModelMap. Essentially, you can seed the data using restful services and change it while the service is running. You can also query the namespace and see what key pairs exist.

 

The basic example is you can get a value like an account balance or a name etc. A complex example might be that instead of a simple value like an account balance you actually store the entire response message in the value of the key pair and fetch that at runtime. This can make a very simple service from a creation standpoint that can adapt over time or for specific test needs. A person can simply post the message they want to respond with by leveraging an argument value for the key name of a key value pair for a specific message. Then the service fetches the message value from the PersistentModelMap Key Value based on a magic string statement.

 

Ok, what does this look like?

 

I found that I would simplify some code down to something like this:

 

{{=com.itko.lisa.test.Environment.getTestRegistry().getMapValue("myNAMESPACE",  "{{=request_myArgumentName}}");}}

 

That fetches the Key value for a Key with the name of the value of my request argument. Lets say the value of "myArguementName" is "Foo" and the value I want to return is "Bar" . I can do this to seed the value on the VSE:

 

PUT http://lisahostname.com:1505/lisa-invoke/persistentMap/myNAMESPACE/Foo/Bar

 

Now at runtime when I make a request call with an argument of "Foo" I get a response that includes "Bar" when I include the above statement.

 

If instead I wanted to store the entire message in a Key pair value I would use this with the message value in the body:

 

POST http://lisahostname.com:1505/lisa-invoke/persistentMap/myNAMESPACE/Foo

 

If I want to check the value of my Key Pair I can do this:

 

GET http://lisahostname.com:1505/lisa-invoke/persistentMap/myNAMESPACE/Foo

 

Or if I want to see all the Key Pairs in the namespace I can do this:

 

GET http://lisahostname.com:1505/lisa-invoke/persistentMap/myNAMESPACE

 

You can also add values from your service...which also is incredibly useful. It allows you to persist data across services running on the same registry. There are settings for how long data is persisted. I think the default is 30 days from the last use of the value. Above I've shown getMapValue, but you can also use:

 

putMapValue(String nameSpace, String key, String value)

 

I hope this is useful for someone.

 

Eric

Outcomes