Skip to content

Instantly share code, notes, and snippets.

@fmarot
fmarot / BackgroundObjectBuilder.java
Created April 4, 2019 14:20
This class contains a builder method that allows to create object with time-consuming constructor in background. Then it can be used as usual from a user perspective. Totally trensparent from user-side apart the construction using the provided builder method.
package com.oleamedical.dbclient.sds;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import java.util.function.Supplier;
@fmarot
fmarot / jenkins-detect-cron
Created April 15, 2019 19:59
do not take this code as-is because I just copy-pasted it from an old test and do not really know anymore if it works correctly. It may help though...
def userIdCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)
boolean buildTriggeredManually = (userIdCause != null);
//boolean buildIsNightly = userIdCause.toString().toLowerCase().contains("trigger") || currentBuild.rawBuild.getCauses().get(0).toString().contains("BranchIndexingCause")
def buildIsNightly = false
currentBuild.upstreamBuilds?.each { b ->
echo "Upstream build: ${b.getFullDisplayName()}"
buildIsNightly = true
}
//def specificCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) // must be set to null once used because it is not serializable
echo "userIdCause = ${userIdCause}, buildTriggeredManually = ${buildTriggeredManually}, buildIsNightly = ${buildIsNightly}" // #debug
@fmarot
fmarot / HttpSessionEventPublisherWithcontextDoesNotStopWorkaround
Last active May 27, 2019 13:48
workaround for spring context re-creating itself when closing after a JUnit test class annotated @SpringBootTest has run
import javax.servlet.http.HttpSessionEvent;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.security.web.session.HttpSessionEventPublisher;
/** This class workaround a bug we observed in JUnit tests when using a full- sds server in AbstractRealDatamanagerTest:
* the problem was that when the spring context was trying to close, then tomcat was finally closed triggering a
* 'sessionDestroyed' event that in turn tried to publish a 'sessionDestroyed' having the effect of reviving the context.
@fmarot
fmarot / pom.xml
Last active February 7, 2020 10:52
surefire 3.0.0-M4 problem
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.teamtter.fake</groupId>
<artifactId>test-fake-module</artifactId>
<version>2.0.0-SNAPSHOT</version>
<properties>
<java.source.target.version>1.8</java.source.target.version>
@fmarot
fmarot / Downloads.wsb
Created July 5, 2024 16:41
a simple Windows Sandbox file
<Configuration>
<!--
<VGpu>Disable</VGpu>
-->
<VGpu>Enable</VGpu>
<Networking>Disable</Networking>
<MappedFolders>
<MappedFolder>
<HostFolder>C:\Users\francois.marot\Downloads</HostFolder>
<SandboxFolder>C:\Host-Downloads</SandboxFolder>