public void TestPutContainerSelect() { using var client = new Client.Client(key, host); // var replica = new Replica(2, ""); //not in policy var replica = new Replica(2, ""); // in policy with others // var replica = new Replica(1, ""); // test only one node put container size var policy = new PlacementPolicy(1, new Replica[] { replica }, null, null); var container = new Container.Container { Version = Refs.Version.SDKVersion(), OwnerId = OwnerID.FromScriptHash(key.PublicKey().PublicKeyToScriptHash()), Nonce = Guid.NewGuid().ToByteString(), BasicAcl = BasicAcl.PublicBasicRule, PlacementPolicy = policy, }; container.Attributes.Add(new Container.Container.Types.Attribute { Key = "CreatedAt", Value = DateTime.UtcNow.ToString(), }); using var source = new CancellationTokenSource(); source.CancelAfter(TimeSpan.FromMinutes(1)); var cid = client.PutContainer(container, context: source.Token).Result; Console.WriteLine(cid.String()); Assert.AreEqual(container.CalCulateAndGetId, cid); }
public void TestPutContainer() { var host = "localhost:8080"; var key = "KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr".LoadWif(); var client = new Client.Client(key, host); var replica = new Replica(1, "*"); var policy = new PlacementPolicy(2, new Replica[] { replica }, null, null); var container = new Container.Container { // Version = Refs.Version.SDKVersion(), // OwnerId = key.ToOwnerID(), Nonce = new Guid().ToByteString(), BasicAcl = (uint)BasicAcl.PublicBasicRule, PlacementPolicy = policy, }; container.Attributes.Add(new Container.Container.Types.Attribute { Key = "CreatedAt", Value = DateTime.UtcNow.ToString(), }); var source = new CancellationTokenSource(); source.CancelAfter(TimeSpan.FromMinutes(1)); var cid = client.PutContainer(source.Token, container); Console.WriteLine(cid.ToBase58String()); Assert.AreEqual(container.CalCulateAndGetID, cid); }
public void TestPutContainerOnlyOne() { using var client = new Client.Client(key, host); var replica1 = new Replica(1, "loc1"); var replica2 = new Replica(1, "loc2"); var selector1 = new Selector("loc1", "Location", Clause.Same, 1, "loc1"); var selector2 = new Selector("loc2", "Location", Clause.Same, 1, "loc2"); var filter1 = new Filter("loc1", "Location", "Shanghai", Netmap.Operation.Eq); var filter2 = new Filter("loc2", "Location", "Shanghai", Netmap.Operation.Ne); var policy = new PlacementPolicy(1, new Replica[] { replica1, replica2 }, new Selector[] { selector1, selector2 }, new Filter[] { filter1, filter2 }); var container = new Container.Container { Version = Refs.Version.SDKVersion(), OwnerId = OwnerID.FromScriptHash(key.PublicKey().PublicKeyToScriptHash()), Nonce = Guid.NewGuid().ToByteString(), BasicAcl = BasicAcl.PublicBasicRule, PlacementPolicy = policy, }; container.Attributes.Add(new Container.Container.Types.Attribute { Key = "CreatedAt", Value = DateTime.UtcNow.ToString(), }); using var source = new CancellationTokenSource(); source.CancelAfter(TimeSpan.FromMinutes(1)); var cid = client.PutContainer(container, context: source.Token).Result; Console.WriteLine(cid.String()); Assert.AreEqual(container.CalCulateAndGetId, cid); }