Configuring VSCode to Use Build Tags in GoLang to Separate Integration and Unit Test Code

One of the ways to separate unit and integration test code in golang is to use build tags.

A TLDR; on build tags is that it is a way to tell the compiler which source code to include or ignore when doing a build.

For example: if we have the following golang code:

// +build integration

package integration

import "testing"

func TestSomething(t *testing.T) {
	// Some test code
}

Then this code will only be compiled if we run the → Continue reading “Configuring VSCode to Use Build Tags in GoLang to Separate Integration and Unit Test Code”

VSCode Change Indent for File Explorer Tree

For me, I have a hard time distinguishing between the folders, sub-folders, and files in the file explorer of VSCode because the indent is not very pronounced.

In order to increase the indent go to File -Preferences -Settings. Search for “indent” and then click on Workbench in the left-hand side navigation pane of the settings window and scroll down to Workbench Tree: Indent and then enter the number of pixels for the tree indentation. I doubled it, going → Continue reading “VSCode Change Indent for File Explorer Tree”

Visual Studio Code Cheat Sheet under Linux

As I’m still learning vscode, I’m keeping track of a cheat sheet for shortcuts and other functionality for the IDE.

The following is under Linux, specifically Debian 10 with XFCE.

Keyboard Shortcuts

  • Edit a string in the entire file that matches exactly the string that you have highlighted. For example: you might have a comment, or a variable name, in a file that you want to find and change globally. Highlight the string and then type CTRL+Shift+L then type the
Continue reading “Visual Studio Code Cheat Sheet under Linux”

VSCode Keyboard Shortcut to Navigate Between Split Panes

In general, I cannot stand using a mouse. It hurts my hand and takes up a ton of time having to move my hand from the keyboard, to the mouse, move the mouse, click, and then move back to the keyboard.

I am a relatively new VSCode user and was pleased that it has a really good vim emulator. I almost always write code in a split screen so that I can either see two different files at the same → Continue reading “VSCode Keyboard Shortcut to Navigate Between Split Panes”

[SOLVED] Upgrading Apache Kafka 2.7 to Java 11 Changes authenticationID sent to ZooKeeper Enabling Only 1 Kafka Broker to r/w znodes

The title of this post is a bit of mouthful and requires a bit more explanation.

I am running a pure open-source version of Kafka (currently running 2.7) and am using SASL/GSSAPI connections between all of the brokers and ZooKeeper. Currently, the whole system, including ZooKeeper, is running Java 8 and it is long-overdue to be upgraded to Java 11.

Upgrading Kafka to Java 11 causes the server to send an incorrect authenticationID String to ZooKeeper which results in the → Continue reading “[SOLVED] Upgrading Apache Kafka 2.7 to Java 11 Changes authenticationID sent to ZooKeeper Enabling Only 1 Kafka Broker to r/w znodes”

message=class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext When Mocking Static Methods in Class

When mocking static classes with Junit4, Mockito and PowerMock, you may see the following log messages after annotating your test class if the code that you are testing is making HTTP connections:

message=class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext

Your annotations for the class (or method) typically include the following:

@RunWith(PowerMockRunner.class)
@PrepareForTest({ SomeClassYouWantToMock.class })

This may cause some confusion, especially if whatever other code that you may have ONLY uses HTTP. Add the following to your annotations to tell → Continue reading “message=class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext When Mocking Static Methods in Class”

Creating a Counter or Progress Bar for a Python Program

I’ve written a number of Python apps where I would like it to print some sort of counter or progress bar to STDOUT to let me know that it is still running instead of locked up or died somehow without me being able to see it.

I had tried using a couple of different existing progress bar related modules but none of them really worked except in a very specific use case.

So, after a bit of futzing around I → Continue reading “Creating a Counter or Progress Bar for a Python Program”

How To Spy and Verify a Static Void Method in Java

The Mockito and PowerMockito libraries for JUnit4 are not always the most intuitive.

Following is an example of how to spy and verify a static void method.

    @Test
    public void testAdd() {

        // Prepare the Utils class to be spied.
        PowerMockito.spy(Utils.class);

        // Run the test and get the actual value from the OUT
        int actualValue = App.add("Test1", 1, 1);

        /*
         * To verify the number of times that we called Utils.doSomething we
         * first need to tell the PowerMockito library 
Continue reading “How To Spy and Verify a Static Void Method in Java”

Configuring rsyslog to rotate log files from log messages streamed to it from a Systemd service

In general, I have moved to writing all of my applications to write their log output to STDOUT. This makes running them on the command line, in an IDE, on a bare metal box, VM, or in a container completely decoupled from how you store and view the logs. No more having multiple logging configs for each flavor of deployment.

In this particular case, I am running an application in a container (but it isn’t necessary that it is in → Continue reading “Configuring rsyslog to rotate log files from log messages streamed to it from a Systemd service”