Code Monkey home page Code Monkey logo

apex-mocks-stress-test's Introduction

Give Me The Lowdown

Hi! Thanks for visiting my Github profile. I'm a Salesforce employee and .net/TypeScript enthusiast.

I'm the author of:

  • the sci-fi/fantasy novel A Good Thing Never Stops
  • the ongoing Salesforce Apex programming series, The Joys Of Apex. I'm always looking for quality SFDC content for the Joys Of Apex — you can reach out if you're interested in contributing a guest post(s)!
  • Apex Rollup, the free & open-source Salesforce custom rollup solution
  • Salesforce Round Robin, which allows for easy & customizable round robin implementations within your Salesforce org

Salesforce Repos

There are a number of repositories I maintain or contribute to related to Apex that may strike your fancy:

  • Apex Rollup - free, CMDT/Invocable/Apex-driven rollup solution aiming to deprecate DLRS. One line of code to install.
  • Apex Mocks — started off as a comparison between a small CRUD wrapper and the larger FFLib library; there are now many branches related to specific Joys Of Apex posts
  • Apex DML Mocking - a very lightweight Factory and Repository implementation allowing for easy mocking and strongly-typed queries
  • lwc-modal — an accessible, composable Lightning Web Component Modal that can be dropped in to any project
  • lwc-paginator — another drop-in LWC, this time for pagination
  • Nebula Logger — The most popular Salesforce logging framework, maintained by my good friend @jongpie. Nebula Logger makes it easy to consolidate logging across both the declarative and code-based parts of your Salesforce org, and has a burgeoning suite of plugins capable of further enhancing your logging functionality, making it easy to do things like log to Slack!

Gatsby Plugins

I've written or contributed to several Gatsby plugins, in addition to contributing to Gatsby itself:

✨ Other Work ✨

I've worked on a variety of e-commerce sites, using everything from Wordpress and Shopify to in-house React / .net MVC / Angular solutions. You can see some of my work on:

In addition, I also run the adventure travel blog She & Jim, which includes a fantastic recipe section 🤤.

apex-mocks-stress-test's People

Contributors

jamessimone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apex-mocks-stress-test's Issues

CrudMock_Tests?

Hey @jamessimone hope you had a nice Thanksgiving! I'm going through Joys of Apex top to bottom again. I noticed you referenced CrudMock_Tests in readme, but I couldn't find it in the source. Am I missing something?

Concurrent writes and thread safety

Hey I just read through your blog here about thread-safe reads/writes in Round Robin.

Could you clarify if/how this is truly read/write safe when 2 separate transactions commit at the same time?

The solution seems to use cache timestamps against the repository initialized timestamps when committing, but there's not a mutex/semaphore around preventing 2 repositories from committing at the same time. The platform cache also does not have a semaphore of its own to prevent concurrent reads/writes.

Org cache supports concurrent reads and writes across multiple simultaneous Apex transactions. For example, a transaction updates the key PetName with the value Fido. At the same time, another transaction updates the same key with the value Felix. Both writes succeed, but one of the two values is chosen arbitrarily as the winner, and later transactions read that one value. However, this arbitrary choice is per key rather than per transaction. For example, suppose one transaction writes PetType="Cat" and PetName="Felix". Then, at the same moment, another transaction writes PetType="Dog" and PetName="Fido". In this case, the PetType winning value could be from the first transaction, and the PetName winning value could be from the second transaction. Subsequent get() calls on those keys would return PetType="Cat" and PetName="Fido".

It seems it's possible for 2 repositories to commit at the same time, which would read the same timestamp from the cache, and they would both succeed in committing using the same index.

Is this an edge case that's not covered?

I think a more resolute solution is to do away with the cache/timestamps and instead query the RoundRobin__c record with the FOR UPDATE clause in assignOwners(), do the assignment, update/release the RoundRobin__c for the next thread. You can then implement your recursive retry attempts if the platform throws a DML exception Or make a queueable where the assignOwners() logic chains itself until it succeeds to avoid the recursive limit.

Interesting note from the docs for FOR UPDATE:

If you attempt to lock a record currently locked by another client, your process waits a maximum of 10 seconds for the lock to be released before acquiring a new lock. If the wait time exceeds 10 seconds, a QueryException is thrown. Similarly, if you attempt to update a record currently locked by another client and the lock isn’t released within a maximum of 10 seconds, a DmlException is thrown.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.