[
https://issues.apache.org/jira/browse/STORM-1902?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15336333#comment-15336333
]
ASF GitHub Bot commented on STORM-1902:
---------------------------------------
Github user vesense commented on a diff in the pull request:
https://github.com/apache/storm/pull/1490#discussion_r67531803
--- Diff:
external/storm-hdfs/src/test/java/org/apache/storm/hdfs/bolt/format/TestSimpleFileNameFormat.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 org.apache.storm.hdfs.bolt.format;
+
+import java.net.UnknownHostException;
+import java.text.SimpleDateFormat;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.storm.task.TopologyContext;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestSimpleFileNameFormat {
+
+ @Test
+ public void testDefaults() {
+ SimpleFileNameFormat format = new SimpleFileNameFormat();
+ format.prepare(null, createTopologyContext());
+ String path = format.getPath();
+ String name = format.getName(1, System.currentTimeMillis());
+
+ Assert.assertEquals("/storm", path);
+ String now = new
SimpleDateFormat("yyyyMMddHHmmss").format(System.currentTimeMillis());
+ Assert.assertEquals(now+".1.txt", name);
+ }
+
+ @Test
+ public void testParameters() {
+ SimpleFileNameFormat format = new SimpleFileNameFormat()
+ .withName("$TIME.$HOST.$COMPONENT.$TASK.$NUM.txt")
+ .withPath("/mypath")
+ .withTimeFormat("yyyy-MM-dd HH:mm:ss");
+ format.prepare(null, createTopologyContext());
+ String path = format.getPath();
+ String name = format.getName(1, System.currentTimeMillis());
+
+ Assert.assertEquals("/mypath", path);
+ String now = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss").format(System.currentTimeMillis());
--- End diff --
Done.
> add a simple & flexible FileNameFormat for storm-hdfs
> -----------------------------------------------------
>
> Key: STORM-1902
> URL: https://issues.apache.org/jira/browse/STORM-1902
> Project: Apache Storm
> Issue Type: Improvement
> Reporter: Xin Wang
> Assignee: Xin Wang
>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)