class_docstr: Tests propagating data service metadata through tf.data service.
class_docstr_tok: ["Tests","propagating","data","service","metadata","through","tf.data","service","."]
code: def testFromDatasetIdCardinality(
      self, dataset_fn, sharding_policy, expected_result
  ):
      cluster = data_service_test_base.TestCluster(num_workers=2)
      dataset = dataset_fn()
      dataset_id = data_service_ops.register_dataset(
          cluster.dispatcher.target, dataset=dataset
      )
      dataset = data_service_ops.from_dataset_id(
          processing_mode=sharding_policy,
          service=cluster.dispatcher.target,
          dataset_id=dataset_id,
          element_spec=dataset.element_spec,
      )
      self.assertEqual(
          self.evaluate(dataset.cardinality()), expected_result
      )
  
imports: import functools
  from absl.testing import parameterized
  from tensorflow.python.data.experimental.kernel_tests.service import test_base
  from tensorflow.python.data.experimental.ops import data_service_ops
  from tensorflow.python.data.experimental.ops import distribute
  from tensorflow.python.data.kernel_tests import test_base
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import combinations
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.ops import script_ops
  from tensorflow.python.platform import test
label_desc: Use image node_id 2 for calling the DataServiceMetadataTest obj's underlying member method code with example usage: obj.testFromDatasetIdCardinality(dataset_fn, sharding_policy, expected_result) without return types