Skip to content

Instantly share code, notes, and snippets.

@ittaiz
ittaiz / CancellingAScheduledFutureWhileItIsRunningHasNoEffect.java
Created December 26, 2013 13:49
cancelling a scheduled future while it is running has no effect
@Test
public void cancellingAScheduledFutureWhileItIsRunningHasNoEffect() {
DeterministicScheduler deterministicScheduler = new DeterministicScheduler();
SchedulerContainer schedulerContainer = new SchedulerContainer(deterministicScheduler);
schedulerContainer.scheduleSelfCancellingTask();
deterministicScheduler.tick(2,TimeUnit.SECONDS);
assertThat(schedulerContainer.runCount(), is(1));
}
public static class SchedulerContainer {
@ittaiz
ittaiz / CancellingAScheduledFutureWhileItIsRunningProhibitsItFromRunningTest.java
Created December 26, 2013 13:22
tests which check how jmock and jdk handle canceling a scheduled future while it is running
@Test
public void cancellingAScheduledFutureWhileItIsRunningProhibitsItFromRunningJMock() throws InterruptedException {
final CountDownLatch scheduledHasStarted = new CountDownLatch(1);
final CountDownLatch scheduledHasBeenCancelled = new CountDownLatch(1);
final AtomicInteger counter = new AtomicInteger();
DeterministicScheduler deterministicScheduler = new DeterministicScheduler();
final ScheduledFuture<?> scheduledFuture = deterministicScheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
scheduledHasStarted.countDown();
@ittaiz
ittaiz / JsonNodeOptionDeserializerTest.scala
Created October 9, 2013 16:12
Test showing classes with an option[JsonNode] stopped serializing
import com.fasterxml.jackson.databind.{ObjectMapper, JsonNode}
import scala.Some
import org.specs2.mutable.SpecificationWithJUnit
import com.fasterxml.jackson.module.scala.DefaultScalaModule
class JsonNodeOptionDeserializerTest extends SpecificationWithJUnit {
"Option[JsonNode] " should {
"serialize its content when contained in an object" in {
val mapper = new ObjectMapper().registerModule(DefaultScalaModule)
val json: String = """{"prop":"value"}"""
@ittaiz
ittaiz / JacksonMultiMapTest.scala
Last active December 20, 2015 18:18
A test with guava and scala modules which fails due to order of module registration
package com.wixpress.report
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.datatype.guava.GuavaModule
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import org.junit._
import Assert._
/**
* @author: ittaiz
@ittaiz
ittaiz / maven_dependency_plugin_specific_version
Created April 28, 2013 05:13
running maven dependency plugin with a specific (2.7) version
mvn org.apache.maven.plugins:maven-dependency-plugin:2.7:tree
@ittaiz
ittaiz / gist:5459609
Last active December 16, 2015 15:59
mvn dependency:tree output showing only spring-beans:3.1.1 is used while in reality spring-beans:3.2.2 was used in runtime. Probably maven dependency plugin bug.
>mvn dependency:tree -Dverbose -Dincludes=org.springframework
...
(omitted for clarity)
...
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ wix-feature-toggle-administration ---
[INFO] artifact org.springframework:spring-beans: checking for updates from central
[INFO] artifact org.springframework:spring-beans: checking for updates from snapshots
[INFO] artifact org.springframework:spring-expression: checking for updates from central
[INFO] artifact org.springframework:spring-expression: checking for updates from snapshots
[INFO] artifact org.springframework:spring-tx: checking for updates from central
@ittaiz
ittaiz / spring-data-mongodb-dependency
Created April 24, 2013 15:39
depending on spring-data-mongodb while excluding spring-beans
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.0.1.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
</exclusions>
@ittaiz
ittaiz / SpringVersionTest
Created April 24, 2013 13:52
A test which checks which jar files some spring classes arrive from on runtime. This was needed since "mvn dependency:tree" showed incorrect results
package com.wixpress.springVersionBug;
import org.junit.*;
import org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory;
import org.springframework.core.GenericTypeResolver;
import java.security.CodeSource;
import static org.hamcrest.Matchers.endsWith;
/**
@ittaiz
ittaiz / Namespace_version_with_hardcoded_queue_name.xml
Created July 3, 2012 07:26
A gist about the need of spring-amqp namespace limitation
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<util:properties id="queueProperties" location="classpath:/queueProperties.properties" />
@ittaiz
ittaiz / mycluster.log
Created January 26, 2012 08:10
Java API Client TRACE discovery log
10:01:21.838 [main] INFO org.elasticsearch.node - [Connors, Curtis] {0.18.7}[4304]: initializing ...
10:01:21.847 [main] INFO org.elasticsearch.plugins - [Connors, Curtis] loaded [], sites []
10:01:22.405 [main] DEBUG org.elasticsearch.threadpool - [Connors, Curtis] creating thread_pool [cached], type [cached], keep_alive [30s]
10:01:22.406 [main] DEBUG org.elasticsearch.threadpool - [Connors, Curtis] creating thread_pool [index], type [cached], keep_alive [5m]
10:01:22.406 [main] DEBUG org.elasticsearch.threadpool - [Connors, Curtis] creating thread_pool [search], type [cached], keep_alive [5m]
10:01:22.406 [main] DEBUG org.elasticsearch.threadpool - [Connors, Curtis] creating thread_pool [percolate], type [cached], keep_alive [5m]
10:01:22.406 [main] DEBUG org.elasticsearch.threadpool - [Connors, Curtis] creating thread_pool [management], type [scaling], min [1], size [20], keep_alive [5m]
10:01:22.407 [main] DEBUG org.elasticsearch.threadpool - [Connors, Curtis] creating thread_pool [merge], type [scalin