本文整理了Java中com.netflix.zuul.scriptManager.ZuulFilterDAO
类的一些代码示例,展示了ZuulFilterDAO
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZuulFilterDAO
类的具体详情如下:
包路径:com.netflix.zuul.scriptManager.ZuulFilterDAO
类名称:ZuulFilterDAO
[英]Interface for data access to persist filters in a persistent store
[中]用于访问持久存储中持久化筛选器的数据的接口
代码示例来源:origin: com.netflix.zuul/zuul-netflix
if (filter_id == null) {
List<String> filterIDs = scriptDAO.getAllFilterIDs();
Map<String, Object> json = new LinkedHashMap<String, Object>();
json.put("filters", filterIDs);
if (Boolean.parseBoolean(request.getParameter("active"))) {
FilterInfo activeEndpoint = scriptDAO.getActiveFilterInfoForFilter(filter_id);
scripts = activeEndpoint == null ? Collections.EMPTY_LIST : Collections.singletonList(activeEndpoint);
} else {
scripts = scriptDAO.getZuulFiltersForFilterId(filter_id);
代码示例来源:origin: com.netflix.zuul/zuul-core
HashMap<String, FilterInfo> setFilters = new HashMap<String, FilterInfo>();
List<FilterInfo> activeScripts = dao.getAllActiveFilters();
if (activeScripts != null) {
for (FilterInfo newFilter : activeScripts) {
List<FilterInfo> canaryScripts = dao.getAllCanaryFilters();
if (canaryScripts != null) {
for (FilterInfo newFilter : canaryScripts) {
List<FilterInfo> newFilters = dao.getAllActiveFilters();
if (newFilters == null) continue;
for (FilterInfo newFilter : newFilters) {
代码示例来源:origin: com.netflix.zuul/zuul-netflix
@SuppressWarnings("unchecked")
@Test
public void testGetFilterIdsIndex() {
ZuulFilterDAO dao = new ZuulFilterDAOCassandra(gateway);
// setup empty response
String fids = "filter1|filter2|filter3";
/* create mock response data */
Row<String, String> row0 = mockRow();
ColumnList<String> columnList0 = mockColumnList(row0);
mockColumn(columnList0, "filter_ids", fids);
// when(response.getRowByIndex(0)).thenReturn(row0);
Iterator<Row<String, String>> iterator = (Iterator<Row<String, String>>) mock(Iterator.class);
when(response.iterator()).thenReturn(iterator);
when(iterator.hasNext()).thenReturn(true, false); // 1 row
when(iterator.next()).thenReturn(row0, (Row) null);
when(gateway.select(anyString())).thenReturn(response);
when(response.isEmpty()).thenReturn(false);
when(response.size()).thenReturn(1);
/* exercise the method we're testing */
List<String> list = dao.getFilterIdsIndex("index");
/* validate responses */
assertEquals(list.size(), 3);
assertEquals(list.get(0), "filter1");
assertEquals(list.get(1), "filter2");
assertEquals(list.get(2), "filter3");
}
代码示例来源:origin: com.netflix.zuul/zuul-netflix
@Test
public void testDownloadSingleScriptPlusErrorHandlerLatest() throws Exception {
/* setup mock */
String filter_id = "name:type";
String action = "DOWNLOAD";
when(request.getPathInfo()).thenReturn("?action=" + action + "&filter_id=" + filter_id);
when(request.getMethod()).thenReturn("GET");
when(request.getParameter("action")).thenReturn(action);
when(request.getParameter("filter_id")).thenReturn(filter_id);
/* setup mock DAO */
ZuulFilterDAO dao = mock(ZuulFilterDAOCassandra.class);
FilterInfo script = mock(FilterInfo.class);
when(dao.getLatestFilterInfoForFilter(filter_id)).thenReturn(script);
when(dao.getFilterInfoForFilter(filter_id, 2)).thenReturn(script);
when(script.getFilterCode()).thenReturn("code");
FilterScriptManagerServlet servlet = getEndpointScriptManagerImplementation(dao);
servlet.service(request, response);
/* verify the default status is used */
verify(response, never()).setStatus(anyInt());
// the writer should not be touched since we need binary, not text
verify(responseWriter).write(anyString());
}
代码示例来源:origin: com.netflix.zuul/zuul-core
doReturn("name:in").when(dao).getFilterIdsRaw(anyString());
when(gateway.getByFilterIds(anyList())).thenReturn(response);
FilterInfo filterInfo = dao.addFilter("code", FilterType.INBOUND, "name", "disable", "order");
代码示例来源:origin: com.netflix.zuul/zuul-netflix
doReturn("name:type").when(dao).getFilterIdsRaw(anyString());
when(gateway.getByFilterIds(anyList())).thenReturn(response);
dao.setFilterActive(filter, 3); // activate the filter that's already active
} catch (Exception e) {
e.printStackTrace();
代码示例来源:origin: com.netflix.zuul/zuul-core
dao = spy(dao);
doReturn("name:in_3").when(dao).getFilterIdsRaw(anyString());
FilterInfo filterInfo = dao.getFilterInfoForFilter(filter, 3);
代码示例来源:origin: com.netflix.zuul/zuul-netflix
doReturn("name:type_4").when(dao).getFilterIdsRaw(anyString());
FilterInfo filterInfo = dao.getLatestFilterInfoForFilter(filter);
代码示例来源:origin: com.netflix.zuul/zuul-core
doReturn("name:in_3").when(dao).getFilterIdsRaw(anyString());
FilterInfo filterInfo = dao.getActiveFilterInfoForFilter(filter);
代码示例来源:origin: com.netflix.zuul/zuul-netflix
dao = spy(dao);
doReturn("name:type_1|name:type_2").when(dao).getFilterIdsRaw(anyString());
List<FilterInfo> list = dao.getZuulFiltersForFilterId(filter);
代码示例来源:origin: com.netflix.zuul/zuul-netflix
filters.add("name3:type");
filters.add("name4:type");
when(dao.getAllFilterIDs()).thenReturn(filters);
代码示例来源:origin: com.netflix.zuul/zuul-netflix
/**
* Not found response for a "list scripts" request.
*
* @throws Exception
*/
@Test
public void testListScriptNotFound() throws Exception {
/* setup mock request to return URI */
when(request.getPathInfo()).thenReturn("?action=LIST&filter_id=name2:type");
when(request.getParameter("action")).thenReturn("LIST");
when(request.getParameter("filter_id")).thenReturn("name:type");
when(request.getMethod()).thenReturn("GET");
/* setup mock DAO */
ZuulFilterDAO dao = mock(ZuulFilterDAOCassandra.class);
List<FilterInfo> emptyResponse = Collections.emptyList();
when(dao.getZuulFiltersForFilterId(anyString())).thenReturn(emptyResponse);
/* construct servlet */
FilterScriptManagerServlet servlet = getEndpointScriptManagerImplementation(dao);
servlet.service(request, response);
// verify that we get a 404 when this endpoint isn't found
verify(response).setStatus(404);
}
代码示例来源:origin: com.netflix.zuul/zuul-netflix
@Test
public void testDownloadSingleScriptRevision() throws Exception {
/* setup mock */
String filter_id = "name:type";
String action = "DOWNLOAD";
when(request.getPathInfo()).thenReturn("?action=" + action + "&filter_id=" + filter_id + "&revision=2");
when(request.getMethod()).thenReturn("GET");
when(request.getParameter("action")).thenReturn(action);
when(request.getParameter("filter_id")).thenReturn(filter_id);
when(request.getParameter("revision")).thenReturn("2");
/* setup mock DAO */
ZuulFilterDAO dao = mock(ZuulFilterDAOCassandra.class);
FilterInfo script = mock(FilterInfo.class);
when(dao.getFilterInfoForFilter(filter_id, 2)).thenReturn(script);
String code = "code";
when(script.getFilterCode()).thenReturn(code);
FilterScriptManagerServlet servlet = getEndpointScriptManagerImplementation(dao);
servlet.service(request, response);
/* verify the default status is used */
verify(response, never()).setStatus(anyInt());
// verify mime-type
verify(response).setContentType("text/plain");
// verify the script is written to the response
verify(responseWriter).write("code");
}
代码示例来源:origin: com.netflix.zuul/zuul-core
@Test
public void testGetScriptForLatestEndpointReturnsNullWhenNotFound() {
ZuulFilterDAO dao = new ZuulFilterDAOCassandra(gateway);
// setup empty response
when(gateway.select(anyString())).thenReturn(response);
when(response.isEmpty()).thenReturn(true);
FilterInfo filterInfo = dao.getLatestFilterInfoForFilter("/unknown/filter");
assertNull(filterInfo);
}
代码示例来源:origin: com.netflix.zuul/zuul-core
@SuppressWarnings("unchecked")
@Test
public void testGetFilterIdsRawIndex() {
ZuulFilterDAO dao = new ZuulFilterDAOCassandra(gateway);
// setup empty response
String fids = "filter1|filter2|filter3";
/* create mock response data */
Row<String, String> row0 = mockRow();
ColumnList<String> columnList0 = mockColumnList(row0);
mockColumn(columnList0, "filter_ids", fids);
// when(response.getRowByIndex(0)).thenReturn(row0);
Iterator<Row<String, String>> iterator = (Iterator<Row<String, String>>) mock(Iterator.class);
when(response.iterator()).thenReturn(iterator);
when(iterator.hasNext()).thenReturn(true, false); // 1 row
when(iterator.next()).thenReturn(row0, (Row) null);
when(gateway.select(anyString())).thenReturn(response);
when(response.isEmpty()).thenReturn(false);
when(response.size()).thenReturn(1);
/* exercise the method we're testing */
String list = dao.getFilterIdsRaw("index");
/* validate responses */
assertEquals(fids, list);
}
代码示例来源:origin: com.netflix.zuul/zuul-netflix
private void handleUploadAction(HttpServletRequest request, HttpServletResponse response) throws IOException {
String filter = handlePostBody(request, response);
if (filter != null) {
FilterInfo filterInfo = null;
try {
filterInfo = FilterVerifier.getInstance().verifyFilter(filter);
} catch (IllegalAccessException e) {
logger.error(e.getMessage(), e);
setUsageError(500, "ERROR: Unable to process uploaded data. " + e.getMessage(), response);
} catch (InstantiationException e) {
logger.error(e.getMessage(), e);
setUsageError(500, "ERROR: Bad Filter. " + e.getMessage(), response);
}
filterInfo = scriptDAO.addFilter(filter, filterInfo.getFilterType(), filterInfo.getFilterName(), filterInfo.getFilterDisablePropertyName(), filterInfo.getFilterOrder());
if (filterInfo == null) {
setUsageError(500, "ERROR: Unable to process uploaded data.", response);
return;
}
response.sendRedirect(redirectPath.get());
}
}
代码示例来源:origin: com.netflix.zuul/zuul-netflix
doReturn("name:type").when(dao).getFilterIdsRaw(anyString());
when(gateway.getByFilterIds(anyList())).thenReturn(response);
FilterInfo filterInfo = dao.addFilter("code", "type", "name", "disable", "order");
代码示例来源:origin: com.netflix.zuul/zuul-core
doReturn("name:in").when(dao).getFilterIdsRaw(anyString());
when(gateway.getByFilterIds(anyList())).thenReturn(response);
dao.setFilterActive(filter, 3); // activate the filter that's already active
} catch (Exception e) {
e.printStackTrace();
代码示例来源:origin: com.netflix.zuul/zuul-netflix
@Test
public void testDownloadSingleScriptLatest() throws Exception {
/* setup mock */
String filter_id = "name:type";
String action = "DOWNLOAD";
when(request.getPathInfo()).thenReturn("?action=" + action + "&filter_id=" + filter_id);
when(request.getMethod()).thenReturn("GET");
when(request.getParameter("action")).thenReturn(action);
when(request.getParameter("filter_id")).thenReturn(filter_id);
/* setup mock DAO */
ZuulFilterDAO dao = mock(ZuulFilterDAOCassandra.class);
FilterInfo script = mock(FilterInfo.class);
when(dao.getLatestFilterInfoForFilter(filter_id)).thenReturn(script);
when(dao.getFilterInfoForFilter(filter_id, 2)).thenReturn(script);
when(script.getFilterCode()).thenReturn("code");
FilterScriptManagerServlet servlet = getEndpointScriptManagerImplementation(dao);
servlet.service(request, response);
/* verify the default status is used */
verify(response, never()).setStatus(anyInt());
// verify mime-type
verify(response).setContentType("text/plain");
// verify the script is written to the response
verify(responseWriter).write("code");
}
代码示例来源:origin: com.netflix.zuul/zuul-netflix
dao = spy(dao);
doReturn("name:type_3").when(dao).getFilterIdsRaw(anyString());
FilterInfo filterInfo = dao.getFilterInfoForFilter(filter, 3);
内容来源于网络,如有侵权,请联系作者删除!