Improved the uploading of file in regard to temporary filename.

Avoid to overwrite the same file for concurrent requests uploading the same filename.
This commit is contained in:
2014-06-11 16:52:22 +02:00
parent ce4c62a989
commit 67641da44d
5 changed files with 357 additions and 116 deletions

View File

@@ -0,0 +1,150 @@
note
description: "Summary description for {TEST_WSF_FILE_UTILITIES}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
TEST_WSF_FILE_UTILITIES
inherit
EQA_TEST_SET
SHARED_EXECUTION_ENVIRONMENT
undefine
default_create, copy
end
feature -- Tests
test_temporary_file_0
do
test_temporary_file (0)
end
test_temporary_file_1_ns
do
test_temporary_file (1)
end
test_temporary_file_100_ns
do
test_temporary_file (100)
end
test_temporary_file_1_s
do
test_temporary_file (1_000_000_000)
end
new_temp_prefix: STRING
local
dt: DATE_TIME
do
create dt.make_now_utc
Result := "TEMP_"
Result.append_integer (dt.date.ordered_compact_date)
Result.append_character ('_')
Result.append_integer (dt.time.compact_time)
Result.append_character ('.')
-- Result.append_integer (dt.time.milli_second)
Result.append_integer ((dt.time.fractional_second * 1_000_000_000).truncated_to_integer)
end
test_temporary_file (a_delay: INTEGER_64)
local
f: detachable FILE
f1,f2: detachable FILE
fac: WSF_FILE_UTILITIES [RAW_FILE]
d: DIRECTORY
logs: STRING_32
l_prefix: STRING
do
create logs.make (0)
create d.make_with_path ((create {PATH}.make_current).extended ("_tmp_"))
d.recursive_create_dir
create fac
l_prefix := new_temp_prefix
f := fac.new_temporary_file (d, l_prefix, "l'<27>t<EFBFBD> est l<>!")
if f /= Void then
create {RAW_FILE}f1.make_with_path (f.path)
f1.open_write
f1.close
logs.append ("f="); logs.append (f.path.name); logs.append ("%N")
if a_delay > 0 then
-- Wait `a_delay' in nanoseconds.
execution_environment.sleep (a_delay)
l_prefix := new_temp_prefix
end
f1 := fac.new_temporary_file (d, l_prefix, "l'<27>t<EFBFBD> est l<>!")
if a_delay > 0 then
-- Wait `a_delay' in nanoseconds.
execution_environment.sleep (a_delay)
l_prefix := new_temp_prefix
end
f2 := fac.new_temporary_file (d, l_prefix, "l'<27>t<EFBFBD> est l<>!")
if f1 /= Void then
logs.append ("f1="); logs.append (f1.path.name); logs.append ("%N")
f.put_string ("test")
f1.put_string ("blabla")
f1.close
else
assert ("able to create new file f1", False)
end
if f2 /= Void then
logs.append ("f2="); logs.append (f2.path.name); logs.append ("%N")
f.put_string ("TEST")
f2.put_string ("BLABLA")
f2.close
else
assert ("able to create new file f1", False)
end
assert ("f1 /= f2", (f1 /= Void and f2 /= Void) and then (not f1.path.is_same_file_as (f2.path)))
f.close
assert ("expected content for f", content (f).same_string ("testTEST"))
assert ("expected content for f1", content (f1).same_string ("blabla"))
assert ("expected content for f2", content (f2).same_string ("BLABLA"))
else
assert ("able to create new file f", False)
end
-- Cleaning
if f /= Void then
f.delete
end
if f1 /= Void then
f1.delete
end
if f2 /= Void then
f2.delete
end
end
content (f: detachable FILE): STRING
do
create Result.make (0)
if f /= Void then
from
f.open_read
assert (f.path.utf_8_name + " is opened", f.is_open_read)
until
f.end_of_file or f.exhausted
loop
f.read_stream (1_024)
Result.append (f.last_string)
end
f.close
end
end
end

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-10-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-10-0 http://www.eiffel.com/developers/xml/configuration-1-10-0.xsd" name="wsf_tests" uuid="C4FF9CDA-B4E4-4841-97E0-7F799B85B657">
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="wsf_tests" uuid="C4FF9CDA-B4E4-4841-97E0-7F799B85B657">
<target name="server">
<root class="TEST" feature="make"/>
<file_rule>
@@ -7,7 +7,7 @@
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option debug="true" warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional">
<option debug="true" warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="transitional" syntax="provisional">
<assertions precondition="true" postcondition="true" check="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="concurrency" value="thread"/>
@@ -22,6 +22,7 @@
</library>
<library name="http" location="..\..\..\network\protocol\http\http-safe.ecf" readonly="false"/>
<library name="http_client" location="..\..\..\network\http_client\http_client-safe.ecf" readonly="false"/>
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
<library name="thread" location="$ISE_LIBRARY\library\thread\thread-safe.ecf"/>
<library name="wsf" location="..\wsf-safe.ecf" readonly="false">
<option>