Permalink
Browse files

more mockable objects

  • Loading branch information...
cadrian committed Oct 26, 2015
1 parent 5b59895 commit 699bbc0d83f1d6940c85432d1e7696f47fd8255a
View
@@ -84,7 +84,11 @@ channel/channel_factory_def.e
channel/client_channel.e
channel/server_channel.e
config/shared_def.e
+extern/environment_def.e
extern/extern_def.e
+extern/file_lock.e
+extern/file_locker_def.e
+extern/filesystem_def.e
EOF
@@ -22,24 +22,23 @@ insert
SHARED_FIFO
CONFIGURABLE
LOGGING
- FILE_TOOLS
create {ANY}
make
feature {CLIENT}
server_running (when_reply: PROCEDURE[TUPLE[BOOLEAN]])
local
- tfr: TEXT_FILE_READ; pid: INTEGER; shared: SHARED
+ tfr: INPUT_STREAM; pid: INTEGER; shared: SHARED
res: BOOLEAN
do
if extern.exists(server_fifo) then
check
extern.exists(server_fifo)
end
- if file_exists(shared.server_pidfile) then
- create tfr.connect_to(shared.server_pidfile)
- if tfr.is_connected then
+ if filesystem.file_exists(shared.server_pidfile) then
+ tfr := filesystem.connect_read(shared.server_pidfile)
+ if tfr /= Void then
tfr.read_line
if tfr.last_string.is_integer then
pid := tfr.last_string.to_integer
@@ -52,12 +51,12 @@ feature {CLIENT}
end
if not res then
- delete(shared.server_pidfile)
+ filesystem.delete(shared.server_pidfile)
end
end
if not res then
- delete(server_fifo)
+ filesystem.delete(server_fifo)
end
end
@@ -93,13 +92,13 @@ feature {CLIENT}
call (query: MESSAGE; when_reply: PROCEDURE[TUPLE[MESSAGE]])
local
- tfw: TEXT_FILE_WRITE; tfr: TEXT_FILE_READ
+ tfw: OUTPUT_STREAM; tfr: INPUT_STREAM
do
log.trace.put_line(once "Calling: #(1)" # query.generating_type)
extern.make(client_fifo)
extern.sleep(25)
- create tfw.connect_to(server_fifo)
- if tfw.is_connected then
+ tfw := filesystem.connect_write(server_fifo)
+ if tfw /= Void then
log.trace.put_line(once "Writing to server...")
tfw.put_line(client_fifo)
streamer.write_message(query, tfw)
@@ -108,12 +107,12 @@ feature {CLIENT}
log.trace.put_line(once "... server fifo written to.")
extern.wait_for(client_fifo)
- create tfr.connect_to(client_fifo)
- if tfr.is_connected then
+ tfr := filesystem.connect_read(client_fifo)
+ if tfr /= Void then
log.trace.put_line(once "Reading from server...")
streamer.read_message(tfr)
tfr.disconnect
- delete(client_fifo)
+ filesystem.delete(client_fifo)
log.trace.put_line(once "... client fifo read from.")
if streamer.error /= Void then
@@ -141,9 +140,9 @@ feature {CLIENT}
cleanup
do
if extern.exists(client_fifo) then
- delete(client_fifo)
+ filesystem.delete(client_fifo)
end
- delete(client_fifo.substring(client_fifo.lower, client_fifo.upper - 5)) -- "/fifo".count
+ filesystem.delete(client_fifo.substring(client_fifo.lower, client_fifo.upper - 5)) -- "/fifo".count
end
feature {}
@@ -161,6 +160,8 @@ feature {}
create Result.make
end
+ filesystem: FILESYSTEM
+
invariant
client_fifo /= Void
@@ -27,7 +27,6 @@ inherit
insert
SHARED_FIFO
LOGGING
- FILE_TOOLS
create {ANY}
make
@@ -59,14 +58,14 @@ feature {SERVER}
continue
local
- query, reply: MESSAGE; tfw: TEXT_FILE_WRITE
+ query, reply: MESSAGE; tfw: OUTPUT_STREAM
do
if channel.last_string.is_empty then
log.trace.put_line(once "Received empty query")
else
log.info.put_line(once "Received query for fifo: #(1)" # channel.last_string)
- create tfw.connect_to(channel.last_string)
- if tfw.is_connected then
+ tfw := filesystem.connect_write(channel.last_string)
+ if tfw /= Void then
streamer.read_message(channel)
if streamer.error /= Void then
log.warning.put_line(once "Error: #(1). Discarding." # streamer.error)
@@ -99,7 +98,7 @@ feature {SERVER}
die_with_code(1)
end
end
- channel.connect_to(server_fifo)
+ channel := filesystem.connect_read_write(server_fifo)
end
disconnect
@@ -109,7 +108,7 @@ feature {SERVER}
cleanup
do
- delete(server_fifo)
+ filesystem.delete(server_fifo)
end
feature {}
@@ -119,16 +118,18 @@ feature {}
log.error.put_line(once "Fifo already exists, not starting server")
die_with_code(1)
end
- create channel.make
+ channel := io
end
- channel: TEXT_FILE_READ_WRITE
+ channel: TERMINAL_INPUT_OUTPUT_STREAM
streamer: MESSAGE_STREAMER
once
create Result.make
end
+ filesystem: FILESYSTEM
+
invariant
channel /= Void
server_fifo /= Void
View
@@ -17,7 +17,6 @@ deferred class CLIENT
insert
GLOBALS
- FILE_TOOLS
feature {}
processor: PROCESSOR
@@ -110,9 +109,9 @@ feature {}
do
if server_running then
check_server_version
- elseif not file_exists(shared.vault_file) then
+ elseif not filesystem.file_exists(shared.vault_file) then
check
- not file_exists(server_pidfile)
+ not filesystem.file_exists(server_pidfile)
end
server_bootstrap
else
@@ -454,4 +453,6 @@ feature {}
action.call([])
end
+ filesystem: FILESYSTEM
+
end -- class CLIENT
@@ -18,9 +18,6 @@ class COMMAND_MERGE
inherit
COMMAND_WITH_REMOTE
-insert
- FILE_TOOLS
-
create {CONSOLE}
make
@@ -65,7 +62,7 @@ feature {}
end
end
- delete(merge_vault)
+ filesystem.delete(merge_vault)
end
merge_vault: FIXED_STRING
@@ -90,4 +87,6 @@ feature {}
end
end
+ filesystem: FILESYSTEM
+
end -- class COMMAND_MERGE
View
@@ -29,22 +29,20 @@ feature {REMOTE}
require
not is_set
local
- sys: SYSTEM; url: like proxy_url
+ url: like proxy_url
do
url := proxy_url
if url /= Void then
- sys.set_environment_variable(once "ALL_PROXY", url.out)
+ environment.set_variable(once "ALL_PROXY", url.out)
log.trace.put_line(once "Proxy set.")
is_set := True
end
end
reset
- local
- sys: SYSTEM
do
if is_set then
- sys.set_environment_variable(once "ALL_PROXY", once "")
+ environment.set_variable(once "ALL_PROXY", once "")
log.trace.put_line(once "Proxy unset.")
is_set := False
end
@@ -228,6 +226,9 @@ feature {REMOTE}
Result := ("pass").intern
end
+feature {}
+ environment: ENVIRONMENT
+
invariant
remote /= Void
specific_config /= Void
View
@@ -75,22 +75,22 @@ feature {COMMAND}
save_file
local
- tfw: TEXT_FILE_WRITE
+ tfw: OUTPUT_STREAM
do
- create tfw.connect_to(filename)
- if tfw.is_connected then
+ tfw := filesystem.connect_write(filename)
+ if tfw /= Void then
write_to(tfw)
tfw.disconnect
end
end
delete_file
local
- ft: FILE_TOOLS; path: FIXED_STRING
+ path: FIXED_STRING
do
path := filename
- if ft.file_exists(path) then
- ft.delete(path)
+ if filesystem.file_exists(path) then
+ filesystem.delete(path)
end
end
@@ -113,6 +113,8 @@ feature {}
end
end
+ filesystem: FILESYSTEM
+
invariant
name /= Void
View
@@ -47,12 +47,12 @@ feature {ANY}
load (local_file: ABSTRACT_STRING)
local
- proc: PROCESS; arg: like arguments; sys: SYSTEM
+ proc: PROCESS; arg: like arguments
do
arg := arguments
if arg /= Void then
arg := once "#(1) #(2)" # arg # local_file
- sys.set_environment_variable(once "SSH_ASKPASS", once "true")
+ environment.set_variable(once "SSH_ASKPASS", once "true")
proc := processor.execute(once "scp", arg)
if proc.is_connected then
proc.wait
@@ -185,4 +185,6 @@ feature {}
Result := ("options").intern
end
+ environment: ENVIRONMENT
+
end -- class SCP
View
@@ -18,8 +18,7 @@ class WEBCLIENT
inherit
CLIENT
rename
- make as make_client,
- delete as ft_delete
+ make as make_client
redefine
read_password_and_send_master,
server_bootstrap,
@@ -448,11 +447,11 @@ feature {}
end
if template_resolver = Void then
filename := "#(1)/#(2)" # conf(config_static_path) # template_name
- create {TEXT_FILE_READ} input.connect_to(filename)
+ input := filesystem.connect_read(filename)
first_response := Void
else
filename := "#(1)/#(2)" # conf(config_template_path) # template_name
- create {TEMPLATE_INPUT_STREAM} input.connect_to(create {TEXT_FILE_READ}.connect_to(filename), template_resolver)
+ create {TEMPLATE_INPUT_STREAM} input.connect_to(filesystem.connect_read(filename), template_resolver)
end
if input.is_connected then
log.trace.put_line("Connected to file: #(1)" # filename)
Oops, something went wrong.

0 comments on commit 699bbc0

Please sign in to comment.