|
| 1 | +use elastic::error::Error; |
| 2 | +use elastic::prelude::*; |
| 3 | +use futures::Future; |
| 4 | +use run_tests::IntegrationTest; |
| 5 | + |
| 6 | +#[derive(Debug, Clone, Copy)] |
| 7 | +pub struct IndexGet; |
| 8 | + |
| 9 | +#[derive(Debug, PartialEq, Serialize, Deserialize, ElasticType)] |
| 10 | +#[elastic(ty = "document", index = "bulk_index")] |
| 11 | +pub struct Doc { |
| 12 | + #[elastic(id)] |
| 13 | + id: String, |
| 14 | + title: String, |
| 15 | + timestamp: Date<DefaultDateMapping>, |
| 16 | +} |
| 17 | + |
| 18 | +impl IntegrationTest for IndexGet { |
| 19 | + type Response = GetResponse<Doc>; |
| 20 | + |
| 21 | + fn kind() -> &'static str { |
| 22 | + "bulk" |
| 23 | + } |
| 24 | + fn name() -> &'static str { |
| 25 | + "index" |
| 26 | + } |
| 27 | + |
| 28 | + // Ensure the index doesn't exist |
| 29 | + fn prepare(&self, client: AsyncClient) -> Box<Future<Item = (), Error = Error>> { |
| 30 | + let delete_res = client.index(Doc::static_index()).delete().send().map(|_| ()); |
| 31 | + |
| 32 | + Box::new(delete_res) |
| 33 | + } |
| 34 | + |
| 35 | + // Index some bulk documents |
| 36 | + fn request(&self, client: AsyncClient) -> Box<Future<Item = Self::Response, Error = Error>> { |
| 37 | + let ops = (0..10).into_iter().map(|i| bulk().index(Doc { |
| 38 | + id: i.to_string(), |
| 39 | + title: "A document title".to_owned(), |
| 40 | + timestamp: Date::build(2017, 03, 24, 13, 44, 0, 0), |
| 41 | + })); |
| 42 | + |
| 43 | + let bulk_res = client |
| 44 | + .bulk() |
| 45 | + .extend(ops) |
| 46 | + .params_fluent(|p| p.url_param("refresh", true)) |
| 47 | + .send(); |
| 48 | + |
| 49 | + let get_res = client.document().get("4").send(); |
| 50 | + |
| 51 | + Box::new(bulk_res.and_then(|_| get_res)) |
| 52 | + } |
| 53 | + |
| 54 | + // Ensure the response contains the expected document |
| 55 | + fn assert_ok(&self, res: &Self::Response) -> bool { |
| 56 | + res.document().map(|doc| &*doc.id) == Some("4") |
| 57 | + } |
| 58 | +} |
0 commit comments