Permalink
Browse files

Small patches for timed-calc post-1.12-merge

  • Loading branch information...
kenzierocks committed Oct 1, 2018
1 parent 776eb24 commit e16dacc11ee0f6df7854989d4e1b0d6068adfd75
@@ -136,7 +136,7 @@ files:
history:
size: 15
expiration: 10
calculation:
timeout: 100
@@ -146,4 +146,4 @@ no-double-slash: false
no-op-permissions: false
debug: false
show-help-on-first-use: true
server-side-cui: true
server-side-cui: true
@@ -181,20 +181,20 @@ public static Expression getInstance() {
}
private void pushInstance() {
Stack<Expression> foo = instance.get();
if (foo == null) {
instance.set(foo = new Stack<>());
Stack<Expression> threadLocalExprStack = instance.get();
if (threadLocalExprStack == null) {
instance.set(threadLocalExprStack = new Stack<>());
}
foo.push(this);
threadLocalExprStack.push(this);
}
private void popInstance() {
Stack<Expression> foo = instance.get();
Stack<Expression> threadLocalExprStack = instance.get();
foo.pop();
threadLocalExprStack.pop();
if (foo.isEmpty()) {
if (threadLocalExprStack.isEmpty()) {
instance.set(null);
}
}

This file was deleted.

Oops, something went wrong.
@@ -22,13 +22,16 @@
import static java.lang.Math.atan2;
import static java.lang.Math.sin;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.internal.expression.lexer.LexerException;
import com.sk89q.worldedit.internal.expression.parser.ParserException;
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
@@ -37,8 +40,13 @@
public class ExpressionTest {
@Before
public void setup() {
WorldEdit.getInstance().getPlatformManager().register(new ExpressionPlatform());
WorldEdit.getInstance().getPlatformManager().handlePlatformReady(new PlatformReadyEvent());
Platform mockPlat = Mockito.mock(Platform.class);
Mockito.when(mockPlat.getConfiguration()).thenReturn(new LocalConfiguration() {
@Override
public void load() {
}
});
WorldEdit.getInstance().getPlatformManager().register(mockPlat);
}
@Test
@@ -172,6 +180,16 @@ public void testQuery() throws Exception {
assertEquals(1, simpleEval("!queryRel(3,4,5,100,200)"), 0);
}
@Test
public void testTimeout() throws Exception {
try {
simpleEval("for(i=0;i<256;i++){for(j=0;j<256;j++){for(k=0;k<256;k++){for(l=0;l<256;l++){ln(pi)}}}}");
fail("Loop was not stopped.");
} catch (EvaluationException e) {
assertTrue(e.getMessage().contains("Calculations exceeded time limit"));
}
}
private double simpleEval(String expressionString) throws ExpressionException {
final Expression expression = compile(expressionString);

0 comments on commit e16dacc

Please sign in to comment.