Personal Programming Notes

To err is human; to debug, divine.

Use One Mocking Framework ONLY

We know that mocking is a critical enabler for unit tests and automated functional tests that don’t require networks and databases and can complete in reasonable time. In a large corporate such as Intuit, different business groups tend to adopt different mocking tools/frameworks for their development and test automation needs. The choice of mocking framework is usually decided by personal preference and experience of few key members of development/automation team. Mocking tools work by integrating with and replacing critical parts of the Java Class Loader. It means that having multiple mocking tools in use will lead to those tools contend to replace the class loader in JVM. This will lead to complex and unexpected consequences and, as a result, random test failures and unreliable tests. For example, we might have tests that work fine locally but start failing when running in combination with others (using other mocking tools) because different mocking frameworks take over the class loader in different order or in different ways.

To fix that, we need to standardize and settle early on a single mocking framework for an organization or a project. Sadly, this is often overlooked before it is too late.

Symlinks in Git

Let’s say we have folders with many symbolic links in them, linking to other files in the same Git repository.

Before
1
2
$ ls -l link
... link -> /path/to/target

Unfortunately after committing into Git, they’ve turned into plain text files. Note that even after committing and pushing into Git, the symlinks still work fine. However, after some branch switches and code merges, the symlinks become actual text files with the link target as the contents.

After
1
2
$ cat link
/path/to/target

WITH Clause in SQL

I am pleasantly surprised that Vertica SQL supports WITH clause, as documented here. WITH syntax as a standard is only defined in SQL-99, also called Common Table Expressions. Therefore, I do not usually expect WITH clause since it is a fairly recent feature in most SQL dialects. For example: WITH clause support is only added into SQLite since Feb 2014.

In summary, the WITH clause allows us to arrange sub-queries in a SQL query in order of human logic. This will make our query much easier to read: we can read from top to bottom like reading a story (i.e., literate programming).

Mocking Current Date and Time in Python

In this post, we looks into unit testing some calendar utilities in Python. A requirement for unit testing those is to “mock” current date and time, i.e., overriding those returned by today and now methods with some specific date values (e.g., a date in future).

AWS: Overview of Services

Amazon Web Services (AWS) is a collection of web services that deliver computing resources (hardware and software) to end-users over the Internet. Not all AWS are equal but for AWS beginners, we usually don’t know which are more important and which are secondary, supporting services. Personally, I am initially overwhelmed by the number of services offered as well as large amount of documentation associated with each service.

This post documents my understanding on some key AWS services and concepts. In this post, AWS concepts and services can be divided into layers. Those layers, from bottom up, are:

  • AWS Infrastructure: Physical data centers and physical network connections.
  • Infrastructure Services (IaaS).
  • Platform Services (PaaS).