|
26 | 26 | //@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
27 | 27 | //@RunWith(JUnit4.class)
|
28 | 28 | //public class MemoryLeaksTest {
|
29 |
| - |
30 | 29 | // private Random random = new Random();
|
31 | 30 | // public static final ArrayList<Double> list = new ArrayList<Double>(1000000);
|
32 | 31 | //
|
33 |
| -// @Test(expected = OutOfMemoryError.class) |
| 32 | +// @Test |
34 | 33 | // public void givenStaticField_whenLotsOfOperations_thenMemoryLeak() throws InterruptedException {
|
35 |
| -// while (true) { |
36 |
| -// int k = random.nextInt(100000); |
37 |
| -// System.out.println(k); |
38 |
| -// Thread.sleep(10000); //to allow GC do its job |
39 |
| -// for (int i = 0; i < k; i++) { |
40 |
| -// list.add(random.nextDouble()); |
41 |
| -// } |
| 34 | +// for (int i = 0; i < 1000000; i++) { |
| 35 | +// list.add(random.nextDouble()); |
42 | 36 | // }
|
| 37 | +// Thread.sleep(10000); //to allow GC do its job |
| 38 | +// } |
43 | 39 | //
|
| 40 | +// |
| 41 | +// @Test |
| 42 | +// public void givenNormalField_whenLotsOfOperations_thenGCWorksFine() throws InterruptedException { |
| 43 | +// addElementsToTheList(); |
| 44 | +// System.gc(); |
| 45 | +// Thread.sleep(10000); //to allow GC do its job |
| 46 | +// } |
| 47 | +// |
| 48 | +// private void addElementsToTheList(){ |
| 49 | +// ArrayList<Double> list = new ArrayList<Double>(1000000); |
| 50 | +// for (int i = 0; i < 1000000; i++) { |
| 51 | +// list.add(random.nextDouble()); |
| 52 | +// } |
44 | 53 | // }
|
45 | 54 | //
|
46 | 55 | // @SuppressWarnings({ "resource" })
|
|
51 | 60 | // str.intern();
|
52 | 61 | // System.out.println("Done");
|
53 | 62 | // }
|
54 |
| - |
| 63 | +// |
55 | 64 | // @Test(expected = OutOfMemoryError.class)
|
56 | 65 | // public void givenURL_whenUnclosedStream_thenOutOfMemory() throws IOException, URISyntaxException {
|
57 | 66 | // String str = "";
|
58 |
| -// URLConnection conn = new URL("http://norvig.com/big.txt").openConnection(); |
| 67 | +// URLConnection conn = new URL("http:norvig.com/big.txt").openConnection(); |
59 | 68 | // BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
|
60 | 69 | // while (br.readLine() != null) {
|
61 | 70 | // str += br.readLine();
|
|
66 | 75 | // @SuppressWarnings("unused")
|
67 | 76 | // @Test(expected = OutOfMemoryError.class)
|
68 | 77 | // public void givenConnection_whenUnclosed_thenOutOfMemory() throws IOException, URISyntaxException {
|
69 |
| -// URL url = new URL("ftp://speedtest.tele2.net"); |
| 78 | +// URL url = new URL("ftp:speedtest.tele2.net"); |
70 | 79 | // URLConnection urlc = url.openConnection();
|
71 | 80 | // InputStream is = urlc.getInputStream();
|
72 | 81 | // String str = "";
|
|
0 commit comments