Flag Monkey (MDC)

Have you ever been in one piece of code and need to alert an unlinked piece of code to what is going on?  This is sometimes very tricky to solve.  Enter Flag Monkey

Problem

I am in a handler function, which calls into a plugin.  The plugin needs to tell the serializer that in certain cases it needs to perform a certain way.  The serializer is not part of the plugin so how can you let it know when it gets to that code, what is going on.

Solution

There is a little-known facility within InsuranceSuite that we can take advantage of that exists across sessions and code boundaries.  This is called MDC, Mapped Diagnostic Context, and is part of the log4j framework. You can read more about it here (opens in a new tab).

Using MDC

One of the simplest ways to use MDC is like a property bag.  You can store items at one place and read them in another.  The issue you have is one of threading.  MDC lives across threads so you need to be very careful about setting and reading data.  One way to handle this is to mark the name with enough context for the read to be thread-aware.

MDC.put(“ehc-${period.Submission.MasterThreadID}”, ehc)

This translates to reading it back as

MDC.get(“ehc-${threadID}”) as ErrorHandlingContextInstance

Notice that the value side of the equation is an object so it is important to cast it upon retrieval.This means that the property consumer needs to be aware of the context around the value.This can and should be encapsulated within the class that uses the MDC so that there is no casting needed beyond the encapsulated class.

Within your class, this can be achieved something like this

static function addErrorContext(period : PolicyPeriod) {
  if (period.Submission.MasterThreadID != null) {
    var ehc = new ErrorHandlingContextInstance()
    MDC.put("ehc-${period.Submission.MasterThreadID}", ehc)
  }
}

static function getErrorContextInstance(threadID : String) : ErrorHandlingContextInstance {
  if (threadID == null) { return null }
  return MDC.get("ehc-${threadID}") as ErrorHandlingContextInstance
}

Another issue that can arise if you are not careful is leaving properties in the bag.  If needed, wrap the use case in a try/finally block to make sure the property is always removed from the MDC.  If you need the value across sessions, maybe for portal, then you would want to put the session ID into the name so it can be distinguished across session boundaries.

Explore CenterTest

CenterTest Generators

Automatically generate test framework assets directly from Guidewire source code. Your tests stay synchronized with your configuration.

Restart Points

Resume failed or suspended scenarios from clearly identified Restart Points to eliminate false failures and optimize test suite execution time.

Role & Session Management

Optimize execution through intelligent session management, and test realistic workflows where multiple users interact with the same transaction.

Time Travel

Automate date-sensitive workflows like renewals, delinquencies, and claims processing. Hassle-free testing of complete policy lifecycles.

Data-Driven Testing

One scenario, hundreds of test variations. Simplify maintenance and scale coverage through data – without duplicating test code.

Document Testing

Automatically validate document generation and verify document content for policy documents, invoices, or claims correspondence.

CenterTest Data Studio

Let analysts own the test data. Business and test analysts change CenterTest test data without development knowledge, on their own machine.

CenterTest Recorder

Record once. Everyone benefits. An analyst walks through the process once in PolicyCenter, BillingCenter or ClaimCenter, and the team gets a video, written steps, the clicks and the checks.

Frequently Asked Questions

Understanding CenterTest

Browse all questions

Ready to elevate your QA practice?

Guidewire test automation,

without the headaches.

that's easy to maintain.

in just two weeks.

future-proofed for cloud.

  • Guidewire test automation, that's easy to maintain.
  • Guidewire test automation, in just two weeks.
  • Guidewire test automation, future-proofed for cloud.
Get Started