Connection refused

Hi all, I am trying to run this example:
/*

  • Copyright (c) 2010-2015 Clark & Parsia, LLC. http://www.clarkparsia.com
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at
  • http://www.apache.org/licenses/LICENSE-2.0
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
    */

package com.complexible.stardog.examples.functions;

import com.complexible.common.rdf.model.Namespaces;
import com.complexible.stardog.Stardog;
import com.complexible.stardog.api.Connection;
import com.complexible.stardog.api.ConnectionConfiguration;
import com.complexible.stardog.api.admin.AdminConnection;
import com.complexible.stardog.api.admin.AdminConnectionConfiguration;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openrdf.query.BindingSet;
import org.openrdf.query.TupleQueryResult;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**

  • @author Michael Grove

  • @since 1.0

  • @version 5.0
    */
    public class TestTitleCaseFunction {
    private static final String DB = "testTitleCase";

    private static Stardog STARDOG;

    @BeforeClass
    public static void beforeClass() throws Exception {
    System.out.println("Setting up DB");
    STARDOG = Stardog.builder().create();

     try (AdminConnection aConn = AdminConnectionConfiguration.toEmbeddedServer()
                                                              .credentials("admin", "admin")
                                                              .connect()) {
     	System.out.println("Connecting to DB");
     	if (aConn.list().contains(DB)) {
     		aConn.drop(DB);
     	}
         System.out.println("Creating DB");
     	aConn.createMemory(DB);
     }
    

    }

    @AfterClass
    public static void afterClass() {
    STARDOG.shutdown();
    }

    @Test
    public void testTitleCase() throws Exception {

     try (Connection aConn = ConnectionConfiguration.to(DB)
                                                    .credentials("admin", "admin")
                                                    .connect()) {
    
     	final String aQuery = "prefix stardog: <" + Namespaces.STARDOG + ">" +
     	                      "select ?str where { bind(stardog:titleCase(\"this sentence does not use title case.\") as ?str) }";
    
     	try (TupleQueryResult aResult = aConn.select(aQuery).execute()) {
     		assertTrue("Should have a result", aResult.hasNext());
    
     		final String aValue = aResult.next().getValue("str").stringValue();
    
     		assertEquals("This Sentence Does Not Use Title Case.", aValue);
    
     		assertFalse("Should have no more results", aResult.hasNext());
     	}
     }
    

    }

    @Test
    public void testTitleCaseTooManyArgs() throws Exception {

     try (Connection aConn = ConnectionConfiguration.to(DB)
                                                    .credentials("admin", "admin")
                                                    .connect()) {
     	final String aQuery = "prefix stardog: <" + Namespaces.STARDOG + ">" +
     	                      "select ?str where { bind(stardog:titleCase(\"this is one argument.\", \"And this is another\") as ?str) }";
    
     	try (TupleQueryResult aResult = aConn.select(aQuery).execute()) {
     		// there should be a result because implicit in the query is the singleton set, so because the bind
     		// should fail due to the value error, we expect a single empty binding
     		assertTrue("Should have a result", aResult.hasNext());
    
     		final BindingSet aBindingSet = aResult.next();
    
     		assertTrue("Should have no bindings", aBindingSet.getBindingNames().isEmpty());
    
     		assertFalse("Should have no more results", aResult.hasNext());
     	}
     }
    

    }

    @Test
    public void testTitleCaseWrongType() throws Exception {

     try (Connection aConn = ConnectionConfiguration.to(DB)
                                                    .credentials("admin", "admin")
                                                    .connect()) {
    
     	final String aQuery = "prefix stardog: <" + Namespaces.STARDOG + ">" +
     	                      "select ?str where { bind(stardog:titleCase(7) as ?str) }";
    
     	try (TupleQueryResult aResult = aConn.select(aQuery).execute()) {
     		// there should be a result because implicit in the query is the singleton set, so because the bind
     		// should fail due to the value error, we expect a single empty binding
     		assertTrue("Should have a result", aResult.hasNext());
    
     		final BindingSet aBindingSet = aResult.next();
    
     		assertTrue("Should have no bindings", aBindingSet.getBindingNames().isEmpty());
    
     		assertFalse("Should have no more results", aResult.hasNext());
     	}
     }
    

    }
    }

But I am getting the error below. Any clue how to fix it?

com.complexible.stardog.StardogException: io.netty.channel.ChannelException: connection refused
at com.complexible.stardog.protocols.client.SPECClientUtil.toStardogException(SPECClientUtil.java:86)
at com.complexible.stardog.protocols.client.SPECClientUtil.toStardogException(SPECClientUtil.java:34)
at com.complexible.stardog.protocols.snarl.client.SNARLDriver.connectAdmin(SNARLDriver.java:181)
at com.complexible.stardog.api.admin.AdminConnectionConfiguration.connect(AdminConnectionConfiguration.java:45)
at com.complexible.stardog.examples.functions.TestTitleCaseFunction.beforeClass(TestTitleCaseFunction.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.net.ConnectException: io.netty.channel.ChannelException: connection refused
at com.complexible.common.protocols.client.rpc.DefaultRPCClient.(DefaultRPCClient.java:125)
at com.complexible.stardog.protocols.snarl.client.admin.AbstractAdminClient.(AbstractAdminClient.java:56)
at com.complexible.stardog.protocols.snarl.client.admin.AdminClientImpl.(AdminClientImpl.java:30)
at com.complexible.stardog.protocols.snarl.client.admin.AdminClientImpl$$FastClassByGuice$$5434d396.newInstance()
at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)
at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:61)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1016)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1012)
at com.google.inject.assistedinject.FactoryProvider2.invoke(FactoryProvider2.java:770)
at com.sun.proxy.$Proxy34.createClient(Unknown Source)
at com.complexible.stardog.protocols.snarl.client.SNARLDriver.connectAdmin(SNARLDriver.java:159)
... 18 more

Hi Samur,

The examples have been updated to work with Stardog 5.0, which includes a number of changes such as the removal of the SNARL protocol. If you want to run this example with Stardog 4.*, you may check out a previous version e.g. [1].

Cheers,
Pavel

[1] GitHub - stardog-union/stardog-examples at 7f46fbe0d39c73be9f68f0a8ff57232081b0342a

Nice! It was fixed by using the right repo.
Thnks!