public static void setupStellarStatically(CuratorFramework client, Optional<String> globalConfig) { /* In order to validate stellar functions, the function resolver must be initialized. Otherwise, those utilities that require validation cannot validate the stellar expressions necessarily. */ Context.Builder builder = new Context.Builder().with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client) ; if(globalConfig.isPresent()) { builder = builder.with(Context.Capabilities.GLOBAL_CONFIG, () -> GLOBAL.deserialize(globalConfig.get())) .with(Context.Capabilities.STELLAR_CONFIG, () -> GLOBAL.deserialize(globalConfig.get())); } else { builder = builder.with(Context.Capabilities.STELLAR_CONFIG, () -> new HashMap<>()); } Context stellarContext = builder.build(); StellarFunctions.FUNCTION_RESOLVER().initialize(stellarContext); }
@Test public void testMissingDb() { context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG , () -> ImmutableMap.of(GeoLiteCityDatabase.GEO_HDFS_FILE, "./fakefile.mmdb") ).build(); String stellar = "GEO_GET()"; try { run(stellar, ImmutableMap.of()); } catch (Exception expected) { Assert.assertTrue(expected.getMessage().contains("File fakefile.mmdb does not exist")); } }
@Test public void testMissingDb() { context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG, () -> ImmutableMap.of(GeoLiteAsnDatabase.ASN_HDFS_FILE, "./fakefile.mmdb") ).build(); String stellar = "ASN_GET()"; try { run(stellar, ImmutableMap.of()); } catch (Exception expected) { Assert.assertTrue(expected.getMessage().contains("File fakefile.mmdb does not exist")); } }
@Before public void setup() throws Exception { context = new Context.Builder() .with(Context.Capabilities.GLOBAL_CONFIG, HashMap::new) .build(); // Store the passwords in the local file system FileUtils.writeStringToFile(new File(basicAuthPasswordPath), basicAuthPassword, StandardCharsets.UTF_8); FileUtils.writeStringToFile(new File(proxyBasicAuthPasswordPath), proxyAuthPassword, StandardCharsets.UTF_8); // By default, the mock server expects a GET request with the path set to /get getUri = String.format("http://localhost:%d/get", mockServerRule.getPort()); mockServerClient.when( request() .withMethod("GET") .withPath("/get")) .respond(response() .withBody("{\"get\":\"success\"}")); }
@Before public void setup() throws Exception { // create the cache Map<String, Object> cacheConfig = ImmutableMap.of( CachingStellarProcessor.MAX_CACHE_SIZE_PARAM, 2, CachingStellarProcessor.MAX_TIME_RETAIN_PARAM, 10, CachingStellarProcessor.RECORD_STATS, true ); cache = CachingStellarProcessor.createCache(cacheConfig); contextWithCache = new Context.Builder() .with(Context.Capabilities.CACHE, () -> cache) .build(); // create the object to test processor = new CachingStellarProcessor(); }
@Test public void testListVarsWithoutVars() { Context context = new Context.Builder() .with(Context.Capabilities.SHELL_VARIABLES, () -> new HashMap<>()) .build(); Object out = run("SHELL_LIST_VARS()", new HashMap<>(), context); Assert.assertEquals(expectedEmptyList, out); } /**
private Context getStellarContext() { Map<String, Object> global = getConfigurations().getGlobalConfig(); return new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> zookeeperClient) .with(Context.Capabilities.GLOBAL_CONFIG, () -> global) .with(Context.Capabilities.STELLAR_CONFIG, () -> global) .build(); }
@Before public void setup() throws Exception { testFolder.create(); context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG , () -> ImmutableMap.of(GeoLiteCityDatabase.GEO_HDFS_FILE, geoHdfsFile.getAbsolutePath()) ) .build(); }
@Before public void setup() throws Exception { testFolder.create(); context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG, () -> ImmutableMap.of(GeoLiteAsnDatabase.ASN_HDFS_FILE, asnHdfsFile.getAbsolutePath()) ).build(); }
@Before public void setup() throws Exception { context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG , () -> ImmutableMap.of(GeoLiteCityDatabase.GEO_HDFS_FILE, geoHdfsFile.getAbsolutePath()) ) .build(); }
@Before public void setup() throws Exception { context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG, () -> ImmutableMap.of(GeoLiteAsnDatabase.ASN_HDFS_FILE, asnHdfsFile.getAbsolutePath()) ).build(); }
@Test public void testListVarsWithVars() { Map<String, VariableResult> variables = ImmutableMap.of( "foo", VariableResult.withExpression(2.0, "1 + 1")); Context context = new Context.Builder() .with(Context.Capabilities.SHELL_VARIABLES , () -> variables) .build(); Object out = run("SHELL_LIST_VARS()", new HashMap<>(), context); Assert.assertEquals(expectedListWithFoo, out); }
public Context getStellarContext() { Map<String, Object> global = getConfigurations().getGlobalConfig(); return new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client) .with(Context.Capabilities.GLOBAL_CONFIG, () -> global) .with(Context.Capabilities.STELLAR_CONFIG, () -> global) .build(); }
/** * Create a function resolver to test. * @param config The configuration for Stellar. */ public static ClasspathFunctionResolver create(Properties config) { ClasspathFunctionResolver resolver = new ClasspathFunctionResolver(); Context context = new Context.Builder() .with(Context.Capabilities.STELLAR_CONFIG, () -> config) .build(); resolver.initialize(context); return resolver; }
/** * Create the execution context for running Stellar. */ public static Context getContext(Map<String, String> globals) { Context context = new Context.Builder() .with(Context.Capabilities.GLOBAL_CONFIG, () -> globals) .with(Context.Capabilities.STELLAR_CONFIG, () -> globals) .build(); StellarFunctions.initialize(context); return context; } }
protected void initializeStellar() { this.stellarContext = new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client) .with(Context.Capabilities.GLOBAL_CONFIG, () -> getConfigurations().getGlobalConfig()) .with(Context.Capabilities.STELLAR_CONFIG, () -> getConfigurations().getGlobalConfig()) .build(); StellarFunctions.initialize(stellarContext); this.functionResolver = StellarFunctions.FUNCTION_RESOLVER(); }
protected void initializeStellar() { stellarContext = new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client) .with(Context.Capabilities.GLOBAL_CONFIG, () -> getConfigurations().getGlobalConfig()) .with(Context.Capabilities.STELLAR_CONFIG, () -> getConfigurations().getGlobalConfig()) .build(); StellarFunctions.initialize(stellarContext); }
protected void initializeStellar() { stellarContext = new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client) .with(Context.Capabilities.GLOBAL_CONFIG, () -> getConfigurations().getGlobalConfig()) .with(Context.Capabilities.STELLAR_CONFIG, () -> getConfigurations().getGlobalConfig()) .build(); StellarFunctions.initialize(stellarContext); }
public StellarTransformationTest(Cache<CachingStellarProcessor.Key, Object> cache) { if(cache == null) { context = Context.EMPTY_CONTEXT(); } else { context = new Context.Builder().with(Context.Capabilities.CACHE, () -> cache).build(); } }
private Context createContext(Optional<CuratorFramework> zkClient) { Context.Builder builder = new Context.Builder(); if (zkClient.isPresent()) { builder.with(Context.Capabilities.ZOOKEEPER_CLIENT, zkClient::get); } builder.with(Context.Capabilities.GLOBAL_CONFIG, () -> globalConfig); builder.with(Context.Capabilities.STELLAR_CONFIG, () -> globalConfig); return builder.build(); }