Permalink
Browse files

bug21092: Clojure: errors in tutorial

tests-added   : run tutorial in prepush
tests-run     : prepush
performance   : no impact

<release-notes>
bug21092: Clojure: errors in tutorial

Enhanced repo-federation to work without rcon-args as was
used in the tutorial. This fixes tutorial example16.

Enhanced value-factory to work with either Repository
or RepositoryConnection. This reduces reflection warnings
in the tutorial.
</release-notes>

Run the clojure tutorial as part of prepush to catch errors.

Tested tutorial with 'lein repl'.

Change-Id: I5e7822c91a4e93b1f4600a5700f615ab812d08ae
Reviewed-on: https://gerrit.franz.com:9080/2217
Reviewed-by: John O'Rourke <jor@franz.com>
Reviewed-by: Ahmon Dancy <dancy@franz.com>
Tested-by: Kevin Layer <layer@franz.com>
  • Loading branch information...
1 parent 18f9e1e commit 54939a29a587b53c24163b07ad83763628daebd4 Mike Hinchey committed with dklayer May 21, 2012
View
@@ -87,8 +87,10 @@
<target name="test"
description="Run tests">
- <run-clj expr="(use 'com.franz.test) (run-tests-exit 'com.franz.agraph.agtest)"/>
- <run-clj expr="(use 'com.franz.test) (run-tests-exit 'com.franz.agraph.stress-conn)"/>
+ <run-clj expr="(use 'com.franz.test) (run-tests-exit
+ 'com.franz.agraph.agtest
+ 'com.franz.agraph.stress-conn
+ 'com.franz.agraph.test.tutorial)"/>
</target>
<target name="prepush"
View
@@ -36,6 +36,8 @@
:url "http://github.com/franzinc/agraph-java-client"
:source-path "src"
:target-dir "dist"
+ :extra-classpath-dirs ["tutorial"]
+ :repl-init com.franz.agraph.tutorial
:warn-on-reflection true
;; TODO :parent [com.franz/agraph-java-client #=(eval (str agraph-version)) :relative-path "../pom.xml"]
:manifest {"Implementation-Title" "Clojure client API for Franz AllegroGraph v4"
@@ -90,14 +90,18 @@
(repo-connection (repo-init (repository catalog repo-name nil)) rcon-args)))
(defn repo-federation
- "rcons: may be of type AGRepository or AGRepositoryConnection"
- [^AGServer server rcons rcon-args]
- (-> (.federate server
- (into-array AGRepository (map #(cond (instance? AGRepository %) %
- (nil? %) nil
- :else (.getRepository ^AGRepositoryConnection %))
- rcons)))
- open repo-init (repo-connection rcon-args)))
+ "rcons: may be of type AGRepository or AGRepositoryConnection
+ rcon-args (optional): if supplied, will also call repo-init, repo-connection, and open, and return the AGRepositoryConnection.
+ Returns: AGRepository or AGRepositoryConnection"
+ ([^AGServer server rcons]
+ (.federate server
+ (into-array AGRepository (map #(cond (instance? AGRepository %) %
+ (nil? %) nil
+ :else (.getRepository ^AGRepositoryConnection %))
+ rcons))))
+ ([^AGServer server rcons rcon-args]
+ (-> (repo-federation server rcons)
+ open repo-init (repo-connection rcon-args))))
(defn ag-server
[url username password]
@@ -119,8 +119,10 @@
repo)
(defn value-factory
- [^RepositoryConnection rcon]
- (.getValueFactory rcon))
+ [rcon]
+ (if (instance? RepositoryConnection rcon)
+ (.getValueFactory ^Repository (.getRepository ^RepositoryConnection rcon))
+ (.getValueFactory ^Repository rcon)))
(defn literal
{:tag Literal}
@@ -141,10 +143,10 @@
(defn resource-array
"creates a primitive java array of Resource from the seq"
- ;;{:tag LResource}
- {:inline (fn [contexts] `^LResource (into-array Resource ~contexts))}
[resources]
- (into-array Resource resources))
+ (if (empty? resources)
+ (java.lang.reflect.Array/newInstance Resource 0)
+ (into-array Resource resources)))
(defn add!
"Add a statement to a repository.
@@ -0,0 +1,17 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Copyright (c) 2008-2012 Franz Inc.
+;; All rights reserved. This program and the accompanying materials
+;; are made available under the terms of the Eclipse Public License v1.0
+;; which accompanies this distribution, and is available at
+;; http://www.eclipse.org/legal/epl-v10.html
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(ns com.franz.agraph.test.tutorial
+ "Tests for AGraph Clojure Tutorial"
+ (:use [clojure test])
+ (:require [com.franz.agraph.tutorial :as tut]
+ [com.franz.agraph.agtest :as agt]))
+
+(deftest run-tutorial
+ (binding [tut/*connection-params* (merge tut/*connection-params* (agt/lookup-server-config))]
+ (tut/example-all)))
@@ -1,5 +1,5 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Copyright (c) 2008-2011 Franz Inc.
+;; Copyright (c) 2008-2012 Franz Inc.
;; All rights reserved. This program and the accompanying materials
;; are made available under the terms of the Eclipse Public License v1.0
;; which accompanies this distribution, and is available at
Oops, something went wrong.

0 comments on commit 54939a2

Please sign in to comment.