[
https://issues.apache.org/jira/browse/OPENNLP-1659?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17901739#comment-17901739
]
ASF GitHub Bot commented on OPENNLP-1659:
-----------------------------------------
rzo1 commented on code in PR #697:
URL: https://github.com/apache/opennlp/pull/697#discussion_r1862297723
##########
opennlp-tools/src/test/java/opennlp/tools/util/AbstractDownloadUtilTest.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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 opennlp.tools.util;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.junit.jupiter.api.BeforeAll;
+
+import opennlp.tools.EnabledWhenCDNAvailable;
+
+import static org.junit.jupiter.api.Assertions.fail;
+
+@EnabledWhenCDNAvailable(hostname = "dlcdn.apache.org")
+public abstract class AbstractDownloadUtilTest {
+
+ private static final String APACHE_CDN = "dlcdn.apache.org";
+
+ @BeforeAll
+ public static void cleanupWhenOnline() {
+ boolean isOnline;
+ try (Socket socket = new Socket()) {
+ socket.connect(new InetSocketAddress(APACHE_CDN, 80),
EnabledWhenCDNAvailable.TIMEOUT_MS);
+ isOnline = true;
+ } catch (IOException e) {
+ // Unreachable, unresolvable or timeout
+ isOnline = false;
+ }
+ // If CDN is available -> go cleanup in preparation of the actual tests
+ if (isOnline) {
+ wipeExistingModelFiles("-tokens-");
Review Comment:
It uses a glob. So all good. Updating.
> Improve DownloadUtil with several enhancements
> ----------------------------------------------
>
> Key: OPENNLP-1659
> URL: https://issues.apache.org/jira/browse/OPENNLP-1659
> Project: OpenNLP
> Issue Type: Improvement
> Reporter: Richard Zowalla
> Assignee: Richard Zowalla
> Priority: Major
> Fix For: 2.5.1
>
>
> DownloadUtil has the need for some improvements:
> * (1) Path handling is done without taking OS specific file separators into
> account
> * (2) Location of download cannot be configured
> * (3) As soon as the classloader loads this class, a HTTP call is made to
> parse download information, which might be bad, if we are in an offline
> environment, etc.
> * (4) There is no indication, if a model is downloaded multiple times. We
> should at least log that situation and have a proper test case for it.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)