Skip to content

Instantly share code, notes, and snippets.

View mchernyavskaya's full-sized avatar

Maryna Cherniavska mchernyavskaya

View GitHub Profile
def 'test get template pages with exception'() {
given:
when:
service.getTemplatePages()
then:
1 * accountService.validateTemplateAccount() >> {
throw new ClientSetupException("Ta da!")
}
import java.util.*;
public class Groups{
private static final List<Character> OPEN = Arrays.asList('(', '{', '[');
private static final List<Character> CLOSE = Arrays.asList(')', '}', ']');
public static boolean groupCheck(String s){
if (s == null || s.length() == 0) {
return true;
}
@mchernyavskaya
mchernyavskaya / bracketsReplace.java
Created February 19, 2017 12:31
Check matching brackets - solution without a stack
public class Groups{
public static boolean groupCheck(String s) {
int len;
do {
len = s.length();
s = s.replace("()", "");
s = s.replace("{}", "");
s = s.replace("[]", "");
} while (len != s.length());
return s.length() == 0;
@mchernyavskaya
mchernyavskaya / ecj.sh
Last active April 5, 2017 14:57
ecj update for tomcat6 and java 8
# stopping web app
sudo service tomcat6 stop
# upload a jar file
wget http://ftp-stud.fht-esslingen.de/pub/Mirrors/eclipse/eclipse/downloads/drops4/R-4.6.2-201611241400/ecj-4.6.2.jar -O /opt/publishthis/ecj-4.6.2.jar
# clean up tomcat temp dirs
sudo rm -rf /opt/publishthis/api/distrib/ROOT
sudo rm -rf /usr/share/tomcat6/work/*
sudo rm -rf /usr/share/tomcat6/cache/*
# log in as appuser to img01/02
sudo service tomcat6 stop
# check
ps aux | grep tomcat
# log in as root to img01/02
wget http://ftp-stud.fht-esslingen.de/pub/Mirrors/eclipse/eclipse/downloads/drops4/R-4.6.2-201611241400/ecj-4.6.2.jar -O /opt/publishthis/ecj-4.6.2.jar
sudo cp /opt/publishthis/ecj-4.6.2.jar /usr/share/java
cd /usr/share/tomcat6/lib/
sudo rm jasper-jdt.jar
private class SuccessCallback implements RetryCallback<Boolean, RuntimeException> {
@Override
public Boolean doWithRetry(RetryContext context) throws RuntimeException {
System.out.println("Success callback: attempt " + context.getRetryCount());
return true;
}
}
private class ExceptionCallback implements RetryCallback<Boolean, Exception> {
@Override
@mchernyavskaya
mchernyavskaya / retryTemplate.java
Last active July 23, 2017 11:33
Spring Retry - create strategy
/*
We want to retry on IOException only.
Other Exceptions won't be retried.
IOException will be retried three times, counting the initial attempt.
*/
final ExceptionClassifierRetryPolicy exRetryPolicy = new ExceptionClassifierRetryPolicy();
exRetryPolicy.setPolicyMap(new HashMap<Class<? extends Throwable>, RetryPolicy>() {{
put(IOException.class, new SimpleRetryPolicy(3));
put(Exception.class, new NeverRetryPolicy());
}});
@mchernyavskaya
mchernyavskaya / retrySuccess.java
Last active July 23, 2017 11:34
Spring Retry Illustration - success
// we do not catch anything here
System.out.println("\n*** Executing successfull callback...");
retryTemplate.execute(new SuccessCallback(), new LoggingRecoveryCallback());
@mchernyavskaya
mchernyavskaya / retryException.java
Last active July 23, 2017 11:34
Spring Retry Illustration - Exception callback
// we catch Exception to allow the program to continue
System.out.println("\n*** Executing Exception callback...");
try {
retryTemplate.execute(new ExceptionCallback(), new LoggingRecoveryCallback());
} catch (Exception e) {
System.out.println("Suppressed Exception");
}
@mchernyavskaya
mchernyavskaya / retryIOException.java
Last active July 23, 2017 11:35
Spring Retry Illustration - IO Exception
// we catch IOException to allow the program to continue
System.out.println("\n*** Executing IO Exception callback...");
try {
retryTemplate.execute(new SpecificExceptionCallback(), new LoggingRecoveryCallback());
} catch (IOException e) {
System.out.println("Suppressed IO Exception");
}