PageRenderTime 546ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/OrphanedGroupsByZoneIdTest.java

http://github.com/jclouds/jclouds
Java | 96 lines | 57 code | 18 blank | 21 comment | 0 complexity | 1f91a89164de71c3c2d929aa42ecf1e1 MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.jclouds.openstack.nova.v2_0.compute.functions;
  18. import static org.testng.Assert.assertEquals;
  19. import java.util.Map;
  20. import java.util.Set;
  21. import org.jclouds.compute.domain.Hardware;
  22. import org.jclouds.compute.domain.Image;
  23. import org.jclouds.compute.domain.NodeMetadata;
  24. import org.jclouds.compute.functions.GroupNamingConvention;
  25. import org.jclouds.domain.Location;
  26. import org.jclouds.domain.LocationBuilder;
  27. import org.jclouds.domain.LocationScope;
  28. import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
  29. import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ServerInZone;
  30. import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
  31. import org.jclouds.openstack.nova.v2_0.parse.ParseServerTest;
  32. import org.testng.annotations.Test;
  33. import com.google.common.base.Predicates;
  34. import com.google.common.base.Supplier;
  35. import com.google.common.base.Suppliers;
  36. import com.google.common.collect.ImmutableMap;
  37. import com.google.common.collect.ImmutableMultimap;
  38. import com.google.common.collect.ImmutableSet;
  39. import com.google.inject.Guice;
  40. /**
  41. *
  42. *
  43. * @author Adrian Cole
  44. */
  45. @Test(testName = "OrphanedGroupsByZoneIdTest")
  46. public class OrphanedGroupsByZoneIdTest {
  47. Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova").description(
  48. "openstack-nova").build();
  49. Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
  50. LocationScope.ZONE).parent(provider).build();
  51. Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
  52. .<String, Location> of("az-1.region-a.geo-1", zone));
  53. GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(GroupNamingConvention.Factory.class);
  54. @Test
  55. public void testWhenComputeServiceSaysAllNodesAreDeadBothGroupsAreReturned() {
  56. ServerInZone withoutHost = new ServerInZone(new ServerInZoneToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1");
  57. ServerInZone withHost = new ServerInZone(new ParseServerTest().expected(), "az-1.region-a.geo-1");
  58. ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
  59. NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
  60. .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers
  61. .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention);
  62. Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost));
  63. assertEquals(new OrphanedGroupsByZoneId(Predicates.<ZoneAndName> alwaysTrue()).apply(set), ImmutableMultimap
  64. .<String, String> builder().putAll("az-1.region-a.geo-1", "sample", "test").build());
  65. }
  66. @Test
  67. public void testWhenComputeServiceSaysAllNodesAreDeadNoGroupsAreReturned() {
  68. ServerInZone withoutHost = new ServerInZone(new ServerInZoneToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1");
  69. ServerInZone withHost = new ServerInZone(new ParseServerTest().expected(), "az-1.region-a.geo-1");
  70. ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
  71. NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
  72. .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers
  73. .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention);
  74. Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost));
  75. assertEquals(new OrphanedGroupsByZoneId(Predicates.<ZoneAndName> alwaysFalse()).apply(set), ImmutableMultimap
  76. .<String, String> of());
  77. }
  78. }