Advertisement
Guest User

Untitled

a guest
Nov 14th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #!/usr/bin/env ruby -G --dev
  2. $: << __dir__
  3. require 'java'
  4. require 'jdbc/postgres'
  5. require 'sequel'
  6. require 'sequel/adapters/jdbc'
  7. require 'thread'
  8.  
  9. # Pre-requisite: Set up a failing "SQL server" to not connect to
  10. #
  11. # nc -l 5700
  12.  
  13. $q = Queue.new
  14.  
  15. # A broken "SQL Server"
  16. t0 = Thread.new do
  17. IO.popen("nc -l 5700") { |io| io.puts($q.read) }
  18. end
  19.  
  20. # Connecting to it, using JDBC
  21. t1 = Thread.new do
  22. dsn = 'jdbc:postgresql://localhost:5700/my_thing'
  23.  
  24. DB = p(Sequel.connect(dsn, login_timeout: 1))
  25.  
  26. # Here, we *actually* connect to the jdbc connect() method
  27. p(DB.tables)
  28. end
  29.  
  30. sleep 3
  31.  
  32. $q.push ""
  33.  
  34. t1.join
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement