Browse Source

Updates/Fortunes (#6868)

* Dockerfile test

* fix run.sh

* Working Docker build and plaintext/json tests implemented and passing..

* julia_server.jl patch

* Update julia_server.jl

Added test for Single Database Query

* Update benchmark_config.json

Updated to reflect addition of SDQ test

* Update julia_server.jl

Now sends JSON object instead of string. Packages have also been fixed. Single Query Test is now passing!!!!

* Testing multiple db queries test

* Testing multiple db queries test

* multiple db queries response formatting changes

* benchmark_config updates

* More multiple queries formatting

* Exception handling for multiple queries

* More handling...

* More handling

* Even more exception handling.....

* Exception handling for multiple queries test

* Exception handling for 0

* Condensing exception handling for multi db queries

* Exception handling fixes...

* exception changes

* Rand num changes

* Rand num changes

* Array changes

* Added StructTypes

* struct fix

* test

* revert test

* Fix reduncancy/formatting code...

* Fixed response headers

* Update README.md

* Update README.md

* Create README.md

* Update julia_server.jl

Added Fortunes test

* Update benchmark_config.json

added fortunes test

* Update julia_server.jl

changed header type

* Update README.md

Added Fortunes test "checkmark"

* Added solution for db updates test

* Update julia_server.jl

Closed DB connections

* Update README.md

added updates

Co-authored-by: donavindebartolo <[email protected]>
Co-authored-by: donavindebartolo <[email protected]>
Co-authored-by: Jayenn <[email protected]>
Co-authored-by: KadeBerry <[email protected]>
abrowao 3 years ago
parent
commit
475e5efd20

+ 2 - 0
frameworks/Julia/Jewelia/README.md

@@ -11,3 +11,5 @@ All tests are located in [julia_server.jl](https://github.com/donavindebartolo/F
 - [x] Single query
 - [x] Single query
 - [x] Multiple queries
 - [x] Multiple queries
 - [x] Plaintext
 - [x] Plaintext
+- [x] Fortunes
+- [x] Updates

+ 2 - 0
frameworks/Julia/Jewelia/benchmark_config.json

@@ -6,6 +6,8 @@
         "plaintext_url": "/plaintext",
         "plaintext_url": "/plaintext",
         "db_url": "/db",
         "db_url": "/db",
         "query_url": "/queries?queries=",
         "query_url": "/queries?queries=",
+        "update_url": "/updates?queries=",
+        "fortune_url": "/fortunes",
         "port": 8080,
         "port": 8080,
         "approach": "Realistic",
         "approach": "Realistic",
         "classification": "None",
         "classification": "None",

+ 75 - 3
frameworks/Julia/Jewelia/julia_server.jl

@@ -44,7 +44,9 @@ HTTP.listen("0.0.0.0" , 8080, reuseaddr = true) do http
 
 
         startwrite(http)
         startwrite(http)
         JSON3.write(http, (JSON3.read(jsonString)))
         JSON3.write(http, (JSON3.read(jsonString)))
-
+        
+        DBInterface.close!(conn)
+        
     elseif occursin("/queries", target)
     elseif occursin("/queries", target)
         HTTP.setheader(http, "Content-Type" => "application/json")
         HTTP.setheader(http, "Content-Type" => "application/json")
         numQueries = -1
         numQueries = -1
@@ -65,7 +67,6 @@ HTTP.listen("0.0.0.0" , 8080, reuseaddr = true) do http
             end
             end
         end
         end
 
 
-        # randNumList = rand(Int64, 1:10000, numQueries)
         conn = DBInterface.connect(MySQL.Connection, "tfb-database", "benchmarkdbuser", "benchmarkdbpass", db="hello_world")
         conn = DBInterface.connect(MySQL.Connection, "tfb-database", "benchmarkdbuser", "benchmarkdbpass", db="hello_world")
 
 
         responseArray = Array{jsonObj}(undef, numQueries)
         responseArray = Array{jsonObj}(undef, numQueries)
@@ -81,8 +82,79 @@ HTTP.listen("0.0.0.0" , 8080, reuseaddr = true) do http
 
 
         startwrite(http)
         startwrite(http)
         JSON3.write(http, responseArray)
         JSON3.write(http, responseArray)
-        # JSON3.write(http, (JSON3.read(responseArray, JSON3.Array)))
+        
+        DBInterface.close!(conn)
+    
+    elseif occursin("/updates", target)
+        HTTP.setheader(http, "Content-Type" => "application/json")
+        numQueries = -1
+
+        try
+            numQueries = parse(Int64, (split(target, "="))[2])
+
+        catch ArgumentError
+            numQueries = 1
+
+        finally
+            if numQueries > 500
+                numQueries = 500
+            end
+
+            if numQueries < 1
+                numQueries = 1
+            end
+        end
 
 
+        conn = DBInterface.connect(MySQL.Connection, "tfb-database", "benchmarkdbuser", "benchmarkdbpass", db="hello_world")
+
+        responseArray = Array{jsonObj}(undef, numQueries)
+        for i in 1:numQueries
+            randId = rand(1:10000)
+            randNum = rand(1:10000)
+            sqlQuery = "SELECT * FROM World WHERE id = $randId"
+            results = DBInterface.execute(conn, sqlQuery)
+            row = first(results)
+            dbNumber = row[2]
+
+            sqlQuery = "UPDATE World SET randomnumber = $randNum WHERE id = $randId"
+            results = DBInterface.execute(conn, sqlQuery)
+            responseArray[i] = JSON3.read("{\"id\":$randId,\"randomNumber\":$randNum}", jsonObj)
+        end
+
+        startwrite(http)
+        JSON3.write(http, responseArray)
+        
+        DBInterface.close!(conn)
+
+    elseif endswith(target, "/fortunes")
+        HTTP.setheader(http, "Content-Type" => "text/html; charset=utf-8")
+    
+        fortunesList = []
+        sqlQuery = "SELECT * FROM fortune"
+        output = "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>"
+        conn = DBInterface.connect(MySQL.Connection, "tfb-database", "benchmarkdbuser", "benchmarkdbpass", db="hello_world")
+        results = DBInterface.execute(conn, sqlQuery)
+    
+        for row in results
+            push!(fortunesList, [string(row[1]), row[2]])
+        end
+    
+        push!(fortunesList, [string(0), "Additional fortune added at request time."])
+    
+        sort!(fortunesList, by = x -> x[2])
+    
+        for fortune in fortunesList
+            id = fortune[1]
+            message = HTTP.Strings.escapehtml(fortune[2])
+            output = string(output, "<tr><td>$id</td><td>$message</td></tr>")
+        end
+    
+        output = string(output, "</table></body></html>")
+    
+        write(http, output)
+        
+        DBInterface.close!(conn)
+        
     else
     else
         HTTP.setstatus(http, 404)
         HTTP.setstatus(http, 404)
         startwrite(http)
         startwrite(http)