Skip to content

Instantly share code, notes, and snippets.

View krmahadevan's full-sized avatar
☠️
Threading ain't hard… Locking is!

Krishnan Mahadevan krmahadevan

☠️
Threading ain't hard… Locking is!
View GitHub Profile
@krmahadevan
krmahadevan / CompletableFuturePriorityQueueExample.java
Created December 12, 2023 05:25
Sample that demonstrates how to use CompletableFuture along with callbacks for listening to task completions which uses a ThreadPoolExecutor which is backed by a PriorityBlockingQueue
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.*;
//Works
public class CompletableFuturePriorityQueueExample {
static class Task implements Comparable<Task> {
private final String name;
@krmahadevan
krmahadevan / setup.md
Last active January 4, 2023 14:52
Quick Setup tutorial with Istio and K8s

Setup

Install minikube by referring to instructions here

Start a mini kube cluster with a higher resource configuration

➜  minikube start --cpus 6 --memory 8192
@krmahadevan
krmahadevan / README.md
Last active October 14, 2022 05:07
Bazel games in Selenium (Java focussed )
package com.springpoc.test;
import com.springpoc.config.SpringConfig;
import com.springpoc.util.WebDriverUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
@krmahadevan
krmahadevan / JSONAwareSoftAssertion.java
Last active May 26, 2022 09:51
A soft assertion implementation backed by org.skyscreamer.jsonassert.JSONAssert
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.skyscreamer.jsonassert.JSONParser;
import org.testng.asserts.IAssert;
import org.testng.asserts.SoftAssert;
public class JSONAwareSoftAssertion extends SoftAssert {
@krmahadevan
krmahadevan / GridInfoExtracter.java
Created February 8, 2012 08:25
A utility class that extracts the actual IP and port to which your remote executions are being routed to by Grid2
public class GridInfoExtracter{
private static String[] getHostNameAndPort(String hostName, int port,
SessionId session) {
String[] hostAndPort = new String[2];
String errorMsg = "Failed to acquire remote webdriver node and port info. Root cause: ";
try {
HttpHost host = new HttpHost(hostName, port);
DefaultHttpClient client = new DefaultHttpClient();
@krmahadevan
krmahadevan / build.gradle
Created October 13, 2021 08:13
A Sample Gradle build file that configures TestNG to be run as a custom task
/*
* This file was generated by the Gradle 'init' task.
*
* This is a general purpose Gradle build.
* Learn more about Gradle by exploring our samples at https://docs.gradle.org/7.2/samples
*/
plugins {
id 'java'
id 'idea'
@krmahadevan
krmahadevan / webconfig.txt
Last active May 6, 2020 16:26
A JSON configuration file that can be used to spawn a webdriver node.
{
"capabilities":
[
{
"browserName":"firefox",
"acceptSslCerts":true,
"javascriptEnabled":true,
"takesScreenshot":true,
"firefox_profile":"",
"maxInstances":5
@krmahadevan
krmahadevan / SampleReporter.java
Created December 27, 2019 04:52
A reporter example that shows how to extract logs for each Test Method in TestNG
import java.util.ArrayList;
import java.util.List;
import org.testng.IReporter;
import org.testng.ISuite;
import org.testng.ISuiteResult;
import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.xml.XmlSuite;
public class SampleReporter implements IReporter {
@krmahadevan
krmahadevan / ScreenshotUsingEventFiringWebDriver
Created September 14, 2012 14:33
Generating Screenshots using EventFiringWebDriver and RemoteWebDriver
package raw.code;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;