Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create keyspace and column family for filter information
- Loading branch information
1 parent
1a554d3
commit 1aecc9d
Showing
6 changed files
with
132 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/io/teknek/intravert/service/ApplicationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
package io.teknek.intravert.service; | ||
|
||
import io.teknek.intravert.action.filter.Filter; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ApplicationContext { | ||
|
||
private Map<String,Filter> filters; | ||
|
||
public ApplicationContext(){ | ||
filters = new HashMap<>(); | ||
} | ||
|
||
public void putFilter(String name, Filter f){ | ||
filters.put(name, f); | ||
} | ||
|
||
public Filter getFilter(String name){ | ||
Filter f = filters.get(name); | ||
//todo get from column family | ||
if (f == null){ | ||
throw new RuntimeException ("filter not found"); | ||
} | ||
return f; | ||
} | ||
} |
6 changes: 0 additions & 6 deletions
6
src/main/java/io/teknek/intravert/service/RequestContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/test/java/io/teknek/intravert/daemon/CreateFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.teknek.intravert.daemon; | ||
|
||
import java.io.IOException; | ||
import java.io.UnsupportedEncodingException; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import junit.framework.Assert; | ||
import io.teknek.intravert.action.ActionFactory; | ||
import io.teknek.intravert.client.Client; | ||
import io.teknek.intravert.model.Constants; | ||
import io.teknek.intravert.model.Operation; | ||
import io.teknek.intravert.model.Request; | ||
import io.teknek.intravert.model.Response; | ||
import io.teknek.nit.NitDesc; | ||
|
||
import org.codehaus.jackson.JsonGenerationException; | ||
import org.codehaus.jackson.map.JsonMappingException; | ||
import org.junit.Test; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Maps; | ||
|
||
public class CreateFilterTest extends BaseIntravertTest { | ||
|
||
@Test | ||
public void createApplicationFilter() throws JsonGenerationException, JsonMappingException, IllegalStateException, UnsupportedEncodingException, IOException, RuntimeException{ | ||
Request request = new Request(); | ||
Map<String,Object> filterDef = new HashMap<String,Object>(); | ||
filterDef.put("spec", NitDesc.NitSpec.GROOVY_CLOSURE.toString()); | ||
filterDef.put("name", "under21"); | ||
filterDef.put("scope", "application"); | ||
filterDef.put("script", "{ row -> if (row['value'].toInteger() > 21) return row else return null }"); | ||
request.getOperations().add(new Operation() | ||
.withId("1").withType(ActionFactory.CREATE_FILTER).withArguments(filterDef)); | ||
Client cl = new Client(); | ||
Response response = cl.post("http://127.0.0.1:7654", request); | ||
List<Map> results = (List<Map>) response.getResults().get("1"); | ||
Assert.assertEquals(new ImmutableMap.Builder<String, Object>().put("result", "ok").build(), results.get(0)); | ||
} | ||
} | ||
/* | ||
Assert.assertEquals( | ||
"{\"exceptionMessage\":null,\"exceptionId\":null,\"results\":{\"2\":[{\"result\":\"ok\"}],\"1\":[{\"session_id\":0}]},\"metaData\":{}}" | ||
, cl.postAsString("http://127.0.0.1:7654", new ObjectMapper().writeValueAsString(request))); | ||
*/ |