blob: d631107fdea3c7562e501c981a1afb4d1a52fc62 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.docproc;
import com.yahoo.docproc.impl.DocprocService;
import com.yahoo.document.DataType;
import com.yahoo.document.DocumentId;
import com.yahoo.document.DocumentPut;
import com.yahoo.document.DocumentType;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* @author Einar M R Rosenvinge
*/
public class FailingWithErrorTestCase {
@Test
public void testErrors() {
DocprocService service = new DocprocService("failing");
DocumentProcessor first = new ErrorThrowingProcessor();
service.setCallStack(new CallStack().addLast(first));
service.setInService(true);
DocumentType type = new DocumentType("test");
type.addField("test", DataType.STRING);
DocumentPut put = new DocumentPut(type, new DocumentId("id:failing:test::1"));
put.getDocument().setFieldValue("test", "foobar");
service.process(put);
assertEquals(1, service.getQueueSize());
try {
while (service.doWork()) { }
fail("Should have gotten OOME here");
} catch (Throwable t) {
//we don't want a finally block in doWork()!
assertEquals(0, service.getQueueSize());
}
assertEquals(0, service.getQueueSize());
}
private class ErrorThrowingProcessor extends DocumentProcessor {
@Override
public Progress process(Processing processing) {
throw new OutOfMemoryError("Einar is out of mem");
}
}
}
|