Search in sources :

Example 1 with MetadataManager

use of com.datastax.oss.driver.internal.core.metadata.MetadataManager in project java-driver by datastax.

the class GraphSupportCheckerTest method addNodeWithDseVersion.

private void addNodeWithDseVersion(InternalDriverContext context, List<Version> dseVersions) {
    MetadataManager manager = mock(MetadataManager.class);
    when(context.getMetadataManager()).thenReturn(manager);
    Metadata metadata = mock(Metadata.class);
    when(manager.getMetadata()).thenReturn(metadata);
    Map<UUID, Node> nodes = new HashMap<>();
    for (Version v : dseVersions) {
        Node node = mock(Node.class);
        Map<String, Object> extras = new HashMap<>();
        extras.put(DseNodeProperties.DSE_VERSION, v);
        when(node.getExtras()).thenReturn(extras);
        nodes.put(UUID.randomUUID(), node);
    }
    when(metadata.getNodes()).thenReturn(nodes);
}
Also used : MetadataManager(com.datastax.oss.driver.internal.core.metadata.MetadataManager) HashMap(java.util.HashMap) Version(com.datastax.oss.driver.api.core.Version) DseProtocolVersion(com.datastax.dse.driver.api.core.DseProtocolVersion) Node(com.datastax.oss.driver.api.core.metadata.Node) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) UUID(java.util.UUID)

Example 2 with MetadataManager

use of com.datastax.oss.driver.internal.core.metadata.MetadataManager in project java-driver by datastax.

the class InsightsClientTest method mockDefaultDriverContext.

private DefaultDriverContext mockDefaultDriverContext() throws UnknownHostException {
    DefaultDriverContext context = mock(DefaultDriverContext.class);
    mockConnectionPools(context);
    MetadataManager manager = mock(MetadataManager.class);
    when(context.getMetadataManager()).thenReturn(manager);
    Metadata metadata = mock(Metadata.class);
    when(manager.getMetadata()).thenReturn(metadata);
    Node node = mock(Node.class);
    when(node.getExtras()).thenReturn(ImmutableMap.of(DseNodeProperties.DSE_VERSION, Objects.requireNonNull(Version.parse("6.0.5"))));
    when(metadata.getNodes()).thenReturn(ImmutableMap.of(UUID.randomUUID(), node));
    DriverExecutionProfile defaultExecutionProfile = mockDefaultExecutionProfile();
    DriverExecutionProfile nonDefaultExecutionProfile = mockNonDefaultRequestTimeoutExecutionProfile();
    Map<String, String> startupOptions = new HashMap<>();
    startupOptions.put(StartupOptionsBuilder.CLIENT_ID_KEY, "client-id");
    startupOptions.put(StartupOptionsBuilder.APPLICATION_VERSION_KEY, "1.0.0");
    startupOptions.put(StartupOptionsBuilder.APPLICATION_NAME_KEY, "app-name");
    startupOptions.put(StartupOptionsBuilder.DRIVER_VERSION_KEY, "2.x");
    startupOptions.put(StartupOptionsBuilder.DRIVER_NAME_KEY, "DataStax Enterprise Java Driver");
    when(context.getStartupOptions()).thenReturn(startupOptions);
    when(context.getProtocolVersion()).thenReturn(DSE_V2);
    DefaultNode contactPoint = mock(DefaultNode.class);
    EndPoint contactEndPoint = mock(EndPoint.class);
    when(contactEndPoint.resolve()).thenReturn(new InetSocketAddress("127.0.0.1", 9999));
    when(contactPoint.getEndPoint()).thenReturn(contactEndPoint);
    when(manager.getContactPoints()).thenReturn(ImmutableSet.of(contactPoint));
    DriverConfig driverConfig = mock(DriverConfig.class);
    when(context.getConfig()).thenReturn(driverConfig);
    Map<String, DriverExecutionProfile> profiles = ImmutableMap.of("default", defaultExecutionProfile, "non-default", nonDefaultExecutionProfile);
    Mockito.<Map<String, ? extends DriverExecutionProfile>>when(driverConfig.getProfiles()).thenReturn(profiles);
    when(driverConfig.getDefaultProfile()).thenReturn(defaultExecutionProfile);
    ControlConnection controlConnection = mock(ControlConnection.class);
    DriverChannel channel = mock(DriverChannel.class);
    EndPoint controlConnectionEndpoint = mock(EndPoint.class);
    when(controlConnectionEndpoint.resolve()).thenReturn(new InetSocketAddress("127.0.0.1", 10));
    when(channel.getEndPoint()).thenReturn(controlConnectionEndpoint);
    when(channel.localAddress()).thenReturn(new InetSocketAddress("127.0.0.1", 10));
    when(controlConnection.channel()).thenReturn(channel);
    when(context.getControlConnection()).thenReturn(controlConnection);
    return context;
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) DefaultNode(com.datastax.oss.driver.internal.core.metadata.DefaultNode) SessionStateForNode(com.datastax.dse.driver.internal.core.insights.schema.SessionStateForNode) Node(com.datastax.oss.driver.api.core.metadata.Node) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) InsightMetadata(com.datastax.dse.driver.internal.core.insights.schema.InsightMetadata) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) MetadataManager(com.datastax.oss.driver.internal.core.metadata.MetadataManager) DefaultDriverContext(com.datastax.oss.driver.internal.core.context.DefaultDriverContext) ControlConnection(com.datastax.oss.driver.internal.core.control.ControlConnection) DefaultNode(com.datastax.oss.driver.internal.core.metadata.DefaultNode) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig)

Example 3 with MetadataManager

use of com.datastax.oss.driver.internal.core.metadata.MetadataManager in project java-driver by datastax.

the class DseTestFixtures method mockNodesInMetadataWithVersions.

public static DefaultDriverContext mockNodesInMetadataWithVersions(DefaultDriverContext mockContext, boolean treatNullAsMissing, Version... dseVersions) {
    // mock bits of the context
    MetadataManager metadataManager = mock(MetadataManager.class);
    Metadata metadata = mock(Metadata.class);
    Map<UUID, Node> nodeMap = new HashMap<>((dseVersions != null) ? dseVersions.length : 1);
    if (dseVersions == null) {
        Node node = mock(Node.class);
        Map<String, Object> nodeExtras = new HashMap<>(1);
        if (!treatNullAsMissing) {
            // put an explicit null in for DSE_VERSION
            nodeExtras.put(DseNodeProperties.DSE_VERSION, null);
        }
        nodeMap.put(UUID.randomUUID(), node);
        when(node.getExtras()).thenReturn(nodeExtras);
    } else {
        for (Version dseVersion : dseVersions) {
            // create a node with DSE version in its extra data
            Node node = mock(Node.class);
            Map<String, Object> nodeExtras = new HashMap<>(1);
            if (dseVersion != null || !treatNullAsMissing) {
                nodeExtras.put(DseNodeProperties.DSE_VERSION, dseVersion);
            }
            nodeMap.put(UUID.randomUUID(), node);
            when(node.getExtras()).thenReturn(nodeExtras);
        }
    }
    // return mocked data when requested
    when(metadata.getNodes()).thenReturn(nodeMap);
    when(metadataManager.getMetadata()).thenReturn(metadata);
    when(mockContext.getMetadataManager()).thenReturn(metadataManager);
    return mockContext;
}
Also used : MetadataManager(com.datastax.oss.driver.internal.core.metadata.MetadataManager) HashMap(java.util.HashMap) Version(com.datastax.oss.driver.api.core.Version) Node(com.datastax.oss.driver.api.core.metadata.Node) DseRowsMetadata(com.datastax.dse.protocol.internal.response.result.DseRowsMetadata) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) UUID(java.util.UUID)

Aggregations

Metadata (com.datastax.oss.driver.api.core.metadata.Metadata)3 Node (com.datastax.oss.driver.api.core.metadata.Node)3 MetadataManager (com.datastax.oss.driver.internal.core.metadata.MetadataManager)3 HashMap (java.util.HashMap)3 Version (com.datastax.oss.driver.api.core.Version)2 UUID (java.util.UUID)2 DseProtocolVersion (com.datastax.dse.driver.api.core.DseProtocolVersion)1 InsightMetadata (com.datastax.dse.driver.internal.core.insights.schema.InsightMetadata)1 SessionStateForNode (com.datastax.dse.driver.internal.core.insights.schema.SessionStateForNode)1 DseRowsMetadata (com.datastax.dse.protocol.internal.response.result.DseRowsMetadata)1 DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)1 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)1 EndPoint (com.datastax.oss.driver.api.core.metadata.EndPoint)1 DriverChannel (com.datastax.oss.driver.internal.core.channel.DriverChannel)1 DefaultDriverContext (com.datastax.oss.driver.internal.core.context.DefaultDriverContext)1 ControlConnection (com.datastax.oss.driver.internal.core.control.ControlConnection)1 DefaultNode (com.datastax.oss.driver.internal.core.metadata.DefaultNode)1 InetSocketAddress (java.net.InetSocketAddress)1