This is an automated email from the ASF dual-hosted git repository.
nswamy pushed a commit to branch java-api
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/java-api by this push:
new 58d4efb Added unit tests for Resource Scope in Java (#12955)
58d4efb is described below
commit 58d4efbe06984b0fef23139b51171cbd56c45c06
Author: Piyush Ghai <[email protected]>
AuthorDate: Wed Oct 24 06:41:08 2018 -0700
Added unit tests for Resource Scope in Java (#12955)
---
.../mxnet/javaapi/ResourceScopeTestSuite.java | 104 +++++++++++++++++++++
scala-package/pom.xml | 4 +-
2 files changed, 106 insertions(+), 2 deletions(-)
diff --git
a/scala-package/core/src/test/java/org/apache/mxnet/javaapi/ResourceScopeTestSuite.java
b/scala-package/core/src/test/java/org/apache/mxnet/javaapi/ResourceScopeTestSuite.java
new file mode 100644
index 0000000..f570ba9
--- /dev/null
+++
b/scala-package/core/src/test/java/org/apache/mxnet/javaapi/ResourceScopeTestSuite.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.mxnet.javaapi;
+
+import org.apache.mxnet.NativeResourceRef;
+import org.apache.mxnet.ResourceScope;
+import org.junit.Test;
+
+import java.util.*;
+import java.util.concurrent.Callable;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class ResourceScopeTestSuite {
+
+ /**
+ * This is a placeholder class to test out whether NDArray References get
collected or not when using
+ * try-with-resources in Java.
+ *
+ */
+ class TestNDArray {
+ NDArray selfArray;
+
+ public TestNDArray(Context context, int[] shape) {
+ this.selfArray = NDArray.ones(context, shape);
+ }
+
+ public boolean verifyIsDisposed() {
+ return this.selfArray.nd().isDisposed();
+ }
+
+ public NativeResourceRef getNDArrayReference() {
+ return this.selfArray.nd().ref();
+ }
+ }
+
+ @Test
+ public void testNDArrayAutoRelease() {
+ TestNDArray test = null;
+
+ try (ResourceScope scope = new ResourceScope()) {
+ test = new TestNDArray(Context.cpu(), new int[]{100, 100});
+ }
+
+ assertTrue(test.verifyIsDisposed());
+ }
+
+ @Test
+ public void testObjectReleaseFromList() {
+ List<TestNDArray> list = new ArrayList<>();
+
+ try (ResourceScope scope = new ResourceScope()) {
+ for (int i = 0;i < 10; i++) {
+ list.add(new TestNDArray(Context.cpu(), new int[] {100, 100}));
+ }
+ }
+
+ assertEquals(list.size() , 10);
+ list.forEach(n -> assertTrue(n.verifyIsDisposed()));
+ }
+
+ @Test
+ public void testObjectReleaseFromMap() {
+ Map<String, TestNDArray> stringToNDArrayMap = new HashMap<>();
+
+ try (ResourceScope scope = new ResourceScope()) {
+ for (int i = 0;i < 10; i++) {
+ stringToNDArrayMap.put(String.valueOf(i),new
TestNDArray(Context.cpu(), new int[] {i, i}));
+ }
+ }
+
+ assertEquals(stringToNDArrayMap.size(), 10);
+ stringToNDArrayMap.forEach((key, value) ->
assertTrue(value.verifyIsDisposed()));
+
+ Map<TestNDArray, String> ndArrayToStringMap = new HashMap<>();
+
+ try (ResourceScope scope = new ResourceScope()) {
+ for (int i = 0;i < 10; i++) {
+ ndArrayToStringMap.put(new TestNDArray(Context.cpu(), new
int[] {i, i}), String.valueOf(i));
+ }
+ }
+
+ assertEquals(ndArrayToStringMap.size(), 10);
+ ndArrayToStringMap.forEach((key, value) ->
assertTrue(key.verifyIsDisposed()));
+
+ }
+}
diff --git a/scala-package/pom.xml b/scala-package/pom.xml
index fe78a62..eb3f6f0 100644
--- a/scala-package/pom.xml
+++ b/scala-package/pom.xml
@@ -190,8 +190,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
- <source>1.6</source>
- <target>1.6</target>
+ <source>1.8</source>
+ <target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>